RE0pts求调!(玄关,先到先得)

P1167 刷题

Hope5365 @ 2024-04-27 15:51:33

#include <iostream>
#include <algorithm>
using namespace std;
#define int long long

const int N = 5e3 + 10,D[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int n,a[N],ans;

bool is_leap(int x)
{
    if (x % 4 != 0) return 0;
    if (x % 100 == 0)
    {
        if (x % 400 == 0) return 1;
        return 0;
    }
    return 1;
}

int get(int y,int m,int d,int h,int M)
{
    int sum = 0;
    for(int i = 1;i < m;i ++)
    {
        if (i == 2)
        {
            if (is_leap(y)) d += 29;
            else d += 28;
        }
        else d += D[i];
    }
    for(int i = 1;i < y;i ++)
    {
        if (is_leap(i)) d += 366;
        else d += 365;
    }
    return M + (h - 1) * 60 + (d - 1) * 3600;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    sort(a + 1,a + n + 1);
    int e,m,d,h,M,e1,m1,d1,h1,M1;
    scanf("%lld-%lld-%lld-%lld:%lld",&e,&m,&d,&h,&M);
    scanf("%lld-%lld-%lld-%lld:%lld",&e1,&m1,&d1,&h1,&M1);
    int t = get(e1,m1,d1,h1,M1) - get(e,m,d,h,M);
    for(int i = 1;i <= n;i ++)
    {
        if (t >= a[i]) ans ++,t -= a[i];
        else break;
    }
    cout << ans << endl;
    return 0;
}

by Cjh20170201 @ 2024-04-27 16:14:41

考虑int爆了?


by shimucheng @ 2024-04-27 16:27:16

int 好像爆了,改long long吧


by Hope5365 @ 2024-04-27 16:45:40

@Cjh20170201 @shimucheng 变成了OWA


by Hope5365 @ 2024-04-27 16:50:12

@Cjh20170201 @shimucheng 可还是0WA


by 123huchenghao @ 2024-06-28 15:23:26

#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;
int n, a[N];
int year = 365, yearr = 366;
int month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int monthr[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
int year1, month1, day1, hour1, min1;
int year2, month2, day2, hour2, min2;
ll time1, time2;
int check(int x){
if(((x%4 == 0) && (x%100 != 0)) || ((x%100 == 0) && (x%400 == 0))) return 1;
else return 0;
}
ll work(ll year3, ll month3, ll day3, ll hour3, ll min3){
int flag = check(year3), time = 0;
for(int i = 0; i < year3; i ++){
if(check(i)) time += yearr*24*60;
else time += year*24*60;
}
ll monthtime = 0;
for(int i = month3 - 1; i >= 0; i --){
if(flag) monthtime += monthr[i]*24*60;
else monthtime += month[i]*24*60;
}
time += min3 + hour3*60 + (day3-1)*24*60 + monthtime;
return time;
}
signed main()
{
scanf("%d",&n);
for(int i = 1; i <= n; i ++) cin >> a[i];
sort(a + 1, a + n + 1);
scanf("%lld-%lld-%lld-%lld:%lld", &year1, &month1, &day1, &hour1, &min1);
 scanf("%lld-%lld-%lld-%lld:%lld", &year2, &month2, &day2, &hour2, &min2);
ll ans = work(year2, month2, day2, hour2, min2) - work(year1, month1, day1, hour1, min1);
int tmp = 0;
for(int i = 1; i <= n; i ++){
if(ans-a[i] >= 0){
tmp ++;
ans -= a[i];
}
}
cout << tmp << endl;
return 0;
}

|