WA 90分求调

P1167 刷题

细数繁星 @ 2023-12-09 20:42:02

错误输入数据:

100
7132
5111
638
7836
3809
1278
9578
7590
8245
5903
7611
4788
6810
1510
3564
3359
6412
996
4966
9801
5807
678
9175
9386
4146
1825
4869
9384
3639
2305
8130
1178
5102
2193
1739
1643
2965
7246
7051
2416
3779
5516
4395
3418
4869
9815
6073
5015
8501
210
3966
4891
8993
2883
5513
3775
799
9986
8190
4664
4361
241
7681
6235
7153
8032
8875
19
9254
1943
2049
8302
1848
9176
8699
6579
8112
4443
5158
8833
9849
6449
3882
2753
4101
1130
9517
4540
5516
9757
1047
3314
2938
576
8635
9440
8509
8
2596
3815
2007-02-05-00:00
2007-03-28-00:00

正确答案:36

程序输出:25

附 code:

// Problem: P1167 刷题
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1167
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Coding by 2044_space_elevator

#include <bits/stdc++.h>
#define rty printf("Yes\n");
#define RTY printf("YES\n");
#define rtn printf("No\n");
#define RTN printf("NO\n");
#define rep(v,b,e) for(int v=b;v<=e;v++)
#define repq(v,b,e) for(int v=b;v<e;v++)
#define rrep(v,e,b) for(int v=b;v>=e;v--)
#define rrepq(v,e,b) for(int v=b;v>e;v--)
#define stg string
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void solve() {

}

#define int ll

int arr[5005];

inline int iseven(int x) {
    return (x % 100 ? !(x % 4) : !(x % 400));
}

inline int day(int n) {
    if (n == 2) {
        return n;
    }
    return (31 - (n == 4 || n == 9 || n == 6 || n == 1));
}

signed main() {
//  int t; cin >> t; while (t--) solve();
    int n;
    cin >> n;
    rep(i, 1, n) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    int tmpa, tmpb, tmpc, tmpd, tmpe, tmp1a, tmp1b, tmp1c, tmp1d, tmp1e;
    scanf("%lld-%lld-%lld-%lld:%lld", &tmpa, &tmpb, &tmpc, &tmpd, &tmpe);
    scanf("%lld-%lld-%lld-%lld:%lld", &tmp1a, &tmp1b, &tmp1c, &tmp1d, &tmp1e);
    int times = 0;
    repq(i, tmpa, tmp1a) {
        times -= (365 + iseven(i));
    }
    repq(i, 1, tmpb) {
        times += day(i);
    }
    repq(i, 1, tmp1b) {
        times -= day(i); 
    }
    times += (iseven(tmpa) && tmpb > 2);
    times -= (iseven(tmp1a) && tmp1b > 2);
    times += (tmpc - tmp1c);
    times *= 24;
    times += tmpd - tmp1d;
    times *= 60;
    times += tmpe - tmp1e;
    times = times * -1;
    int cnt = 0, sum = 0;
    rep(i, 1, n) {
        sum += arr[i];
        if (sum > times) {
            break;
        }
        cnt++;
    }
    cout << cnt;
    return 0;
}

by wangzhongqian @ 2024-04-12 20:03:07

#include <bits/stdc++.h>
#define rty printf("Yes\n");
#define RTY printf("YES\n");
#define rtn printf("No\n");
#define RTN printf("NO\n");
#define rep(v,b,e) for(int v=b;v<=e;v++)
#define repq(v,b,e) for(int v=b;v<e;v++)
#define rrep(v,e,b) for(int v=b;v>=e;v--)
#define rrepq(v,e,b) for(int v=b;v>e;v--)
#define stg string
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void solve() {

}

#define int ll

int arr[5005];

inline int iseven(int x) {
    return (x % 100 ? !(x % 4) : !(x % 400));
}

inline int day(int n) {
    if (n == 2) {
        return 28;//2月28天
    }
    return (31 - (n == 4 || n == 9 || n == 6 || n == 1));
}

signed main() {
//  int t; cin >> t; while (t--) solve();
    int n;
    cin >> n;
    rep(i, 1, n) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    int tmpa, tmpb, tmpc, tmpd, tmpe, tmp1a, tmp1b, tmp1c, tmp1d, tmp1e;
    scanf("%lld-%lld-%lld-%lld:%lld", &tmpa, &tmpb, &tmpc, &tmpd, &tmpe);
    scanf("%lld-%lld-%lld-%lld:%lld", &tmp1a, &tmp1b, &tmp1c, &tmp1d, &tmp1e);
    int times = 0;
    repq(i, tmpa, tmp1a) {
        times -= (365 + iseven(i));
    }
    repq(i, 1, tmpb) {
        times += day(i);
    }
    repq(i, 1, tmp1b) {
        times -= day(i);
    }
    times += (iseven(tmpa) && tmpb > 2);
    times -= (iseven(tmp1a) && tmp1b > 2);
    times += (tmpc - tmp1c);
    times *= 24;
    times += tmpd - tmp1d;
    times *= 60;
    times += tmpe - tmp1e;
    times = times * -1;
    int cnt = 0, sum = 0;
    rep(i, 1, n) {
        sum += arr[i];
        if (sum > times) {
            break;
        }
        cnt++;
    }
    cout << cnt;
    return 0;
}

by wangzhongqian @ 2024-04-13 14:55:32

@2044_space_elevator

day函数里判断为2后return 28而不是n


|