Submission #46867

#TimeUsernameProblemLanguageResultExecution timeMemory
46867khohkoCandies (JOI18_candies)C++17
8 / 100
5058 ms469404 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...