Submission #914180

#TimeUsernameProblemLanguageResultExecution timeMemory
914180PieArmyKpart (eJOI21_kpart)C++17
30 / 100
2013 ms2096 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); int t;cin>>t; while(t--){ int n;cin>>n; int arr[n]; int pref[n+1];pref[0]=0; for(int i=0;i<n;i++){cin>>arr[i];pref[i+1]=pref[i]+arr[i];} vector<int>dp(100001,-1); dp[0]=0; vector<int>nex(n+1,-1); vector<int>prev(0); int mx=0; for(int i=0;i<n;i++){ prev.resize(pref[i+1]+2,-1); prev[pref[i+1]+1]=mx; int l=prev.back(),r=pref[i+1]+1; while(l!=-1){ while(prev[r]>=l+arr[i]){ r=prev[r]; } if(r==l+arr[i]){ dp[l+arr[i]]=max(dp[l+arr[i]],dp[l]); } else{ if(r==pref[i+1]+1)mx=l+arr[i]; prev[l+arr[i]]=prev[r]; prev[r]=l+arr[i]; dp[l+arr[i]]=dp[l]; } l=prev[l]; } prev[pref[i+1]+1]=-1; dp[arr[i]]=i; int las=0,pos=nex[0]; while(pos!=-1){ int sum=pref[i+1]-pref[i+1-pos]; if((sum&1)||dp[sum>>1]<=i-pos)nex[las]=nex[pos]; else las=pos; pos=nex[pos]; } if((pref[i+1]&1)==0&&dp[pref[i+1]>>1]!=-1)nex[las]=i+1; } vector<int>ans; int pos=nex[0]; while(pos!=-1){ ans.push_back(pos); pos=nex[pos]; } cout<<ans.size()<<" "; for(int x:ans)cout<<x<<" "; cout<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...