Submission #934334

# Submission time Handle Problem Language Result Execution time Memory
934334 2024-02-27T07:30:14 Z alexander707070 Candies (JOI18_candies) C++14
8 / 100
5000 ms 4900 KB
#include<bits/stdc++.h>
#define MAXN 500007
using namespace std;

const long long inf=1e17;

int n,best;
long long a[MAXN],sum,maxs,curr;
bool used[MAXN];

long long calc(int x){
    long long res=a[x];

    for(int i=x-1;used[i] and i>=1;i-=2){
        res-=a[i]; res+=a[i-1];
        if(i-1==0)return -inf;
    }
    for(int i=x+1;used[i] and i<=n;i+=2){
        res-=a[i]; res+=a[i+1];
        if(i+1==n+1)return -inf;
    }

    return res;
}

void mark(int x){
    used[x]=true;

    for(int i=x-1;used[i] and i>=1;i-=2){
        used[i]=false; 
        used[i-1]=true;
    }
    for(int i=x+1;used[i] and i<=n;i+=2){
        used[i]=false;
        used[i+1]=true;
    }
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    for(int i=1;i<=n/2+n%2;i++){
        maxs=-inf;

        for(int f=1;f<=n;f++){
            if(used[f])continue;

            curr=calc(f);
            if(curr>maxs){
                maxs=curr; best=f;
            }
        }

        mark(best); sum+=maxs;

        maxs=0;
        for(int f=1;f<=n;f++){
            if(used[f])maxs++;
        }
        if(maxs!=i)cout<<1/0;

        cout<<sum<<"\n";
    }

    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:68:27: warning: division by zero [-Wdiv-by-zero]
   68 |         if(maxs!=i)cout<<1/0;
      |                          ~^~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2396 KB Output is correct
2 Correct 16 ms 2536 KB Output is correct
3 Correct 14 ms 2396 KB Output is correct
4 Correct 15 ms 2552 KB Output is correct
5 Correct 17 ms 2392 KB Output is correct
6 Correct 14 ms 2396 KB Output is correct
7 Correct 14 ms 2392 KB Output is correct
8 Correct 14 ms 2396 KB Output is correct
9 Correct 16 ms 2532 KB Output is correct
10 Correct 17 ms 2528 KB Output is correct
11 Correct 15 ms 2560 KB Output is correct
12 Correct 15 ms 2396 KB Output is correct
13 Correct 15 ms 2396 KB Output is correct
14 Correct 14 ms 2544 KB Output is correct
15 Correct 14 ms 2392 KB Output is correct
16 Correct 14 ms 2396 KB Output is correct
17 Correct 15 ms 2396 KB Output is correct
18 Correct 15 ms 2396 KB Output is correct
19 Correct 18 ms 2396 KB Output is correct
20 Correct 17 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2396 KB Output is correct
2 Correct 16 ms 2536 KB Output is correct
3 Correct 14 ms 2396 KB Output is correct
4 Correct 15 ms 2552 KB Output is correct
5 Correct 17 ms 2392 KB Output is correct
6 Correct 14 ms 2396 KB Output is correct
7 Correct 14 ms 2392 KB Output is correct
8 Correct 14 ms 2396 KB Output is correct
9 Correct 16 ms 2532 KB Output is correct
10 Correct 17 ms 2528 KB Output is correct
11 Correct 15 ms 2560 KB Output is correct
12 Correct 15 ms 2396 KB Output is correct
13 Correct 15 ms 2396 KB Output is correct
14 Correct 14 ms 2544 KB Output is correct
15 Correct 14 ms 2392 KB Output is correct
16 Correct 14 ms 2396 KB Output is correct
17 Correct 15 ms 2396 KB Output is correct
18 Correct 15 ms 2396 KB Output is correct
19 Correct 18 ms 2396 KB Output is correct
20 Correct 17 ms 2396 KB Output is correct
21 Execution timed out 5037 ms 4900 KB Time limit exceeded
22 Halted 0 ms 0 KB -