Submission #46867

# Submission time Handle Problem Language Result Execution time Memory
46867 2018-04-24T09:11:15 Z khohko Candies (JOI18_candies) C++17
8 / 100
5000 ms 469404 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define lol long long
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define MAX ((lol)(1e15+100))
#define MX ((lol)(4e9+100))
#define ARRS ((lol)(1e6+100))
#define MOD ((lol)(1e9+7))
#define EP ((double)(1e-9))
#define EPS ((double)(1e-8))
#define pb push_back
#define PI ((double)3.141592653)
#define LG 21

map<pair<pair<pair<ll,ll> ,pair<ll,ll> >,ll> ,ll> mp;
ll a[ARRS];
ll n;

ll go(ll l,ll r,ll cl,ll cr,ll k){
    if(mp[{{{l,r},{cl,cr}},k}])return mp[{{{l,r},{cl,cr}},k}];
    ll pas=-MAX;
    if(!k)return 0;
    if(l==r&&cl==cr&&cl==1&&k==1)
        return a[l];
    else if(l==r&&k)return -MAX;
    else if(l==r)return 0;
    ll m=l+r>>1;
   // cout<<l<<" "<<r<<" "<<m<<" "<<cl<<" "<<cr<<" "<<k<<" "<<pas<<endl;
    if((r-l-(cl^1)-(cr^1)+2)/2<k)return -MAX;

    //cout<<endl;
    for(int i=0; i<=k; i++){
        ll t,c;

        t=go(l,m,cl,1,i);
        c=go(m+1,r,0,cr,k-i);
        pas=max(pas,t+c);
       // cout<<i<<" "<<t<<" "<<l<<" "<<m<<" "<<cl<<" "<<1<<" "<<i<<" "<<c<<endl;

        t=go(l,m,cl,0,i);
        c=go(m+1,r,1,cr,k-i);
       // cout<<i<<" "<<t<<" "<<c<<endl;
        pas=max(pas,t+c);

    }
   // cout<<l<<" "<<r<<" "<<cl<<" "<<cr<<" "<<k<<" "<<pas<<" "<<m<<endl;
    mp[{{{l,r},{cl,cr}},k}]=pas;
    return mp[{{{l,r},{cl,cr}},k}];
}

int main(){
    #ifdef KHOKHO
        freopen("in.in","r",stdin);
        freopen("out.out","w",stdout);
    #endif // KHOKHO
    ios::sync_with_stdio(0);
    ll h,w,n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=1; i<=(n+1)/2; i++)
        cout<<go(0,n-1,1,1,i)<<endl;
}

Compilation message

candies.cpp: In function 'long long int go(long long int, long long int, long long int, long long int, long long int)':
candies.cpp:32:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     ll m=l+r>>1;
          ~^~
candies.cpp: In function 'int main()':
candies.cpp:62:8: warning: unused variable 'h' [-Wunused-variable]
     ll h,w,n;
        ^
candies.cpp:62:10: warning: unused variable 'w' [-Wunused-variable]
     ll h,w,n;
          ^
# Verdict Execution time Memory Grader output
1 Correct 1554 ms 9436 KB Output is correct
2 Correct 1586 ms 9572 KB Output is correct
3 Correct 1488 ms 9828 KB Output is correct
4 Correct 1553 ms 9828 KB Output is correct
5 Correct 1514 ms 9952 KB Output is correct
6 Correct 1549 ms 9980 KB Output is correct
7 Correct 1534 ms 10072 KB Output is correct
8 Correct 1535 ms 10164 KB Output is correct
9 Correct 1645 ms 10164 KB Output is correct
10 Correct 1536 ms 10164 KB Output is correct
11 Correct 1599 ms 10164 KB Output is correct
12 Correct 1607 ms 10204 KB Output is correct
13 Correct 1586 ms 10288 KB Output is correct
14 Correct 1570 ms 10288 KB Output is correct
15 Correct 1596 ms 10332 KB Output is correct
16 Correct 1908 ms 10332 KB Output is correct
17 Correct 1650 ms 10332 KB Output is correct
18 Correct 1563 ms 10344 KB Output is correct
19 Correct 1571 ms 10492 KB Output is correct
20 Correct 1610 ms 10492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1554 ms 9436 KB Output is correct
2 Correct 1586 ms 9572 KB Output is correct
3 Correct 1488 ms 9828 KB Output is correct
4 Correct 1553 ms 9828 KB Output is correct
5 Correct 1514 ms 9952 KB Output is correct
6 Correct 1549 ms 9980 KB Output is correct
7 Correct 1534 ms 10072 KB Output is correct
8 Correct 1535 ms 10164 KB Output is correct
9 Correct 1645 ms 10164 KB Output is correct
10 Correct 1536 ms 10164 KB Output is correct
11 Correct 1599 ms 10164 KB Output is correct
12 Correct 1607 ms 10204 KB Output is correct
13 Correct 1586 ms 10288 KB Output is correct
14 Correct 1570 ms 10288 KB Output is correct
15 Correct 1596 ms 10332 KB Output is correct
16 Correct 1908 ms 10332 KB Output is correct
17 Correct 1650 ms 10332 KB Output is correct
18 Correct 1563 ms 10344 KB Output is correct
19 Correct 1571 ms 10492 KB Output is correct
20 Correct 1610 ms 10492 KB Output is correct
21 Execution timed out 5058 ms 469404 KB Time limit exceeded
22 Halted 0 ms 0 KB -