# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
592955 | 2022-07-09T22:05:29 Z | TimDee | Kpart (eJOI21_kpart) | C++14 | 1901 ms | 391396 KB |
#include <bits/stdc++.h> using namespace std; #define paiu return #define moment 0; #define int long long #define double long double #define ll long long #define forr(i,x) for (int i=0; i<x; i++) #define forn(i,x) for (int i=0; i<x; i++) #define vi(a,n) vector<int> a(n,0) //cringe define #define vii(a,n) vi(a,n); forr(i,n) cin>>a[i]; vector<int> ___makeprefsum(vector<int>&a) { int n=a.size(); vi(pr,n+1); forn(i,n) pr[i+1]=pr[i]+a[i]; return pr; } #define prefsum(pr,a) vector<int> pr=___makeprefsum(a); #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define pb(x) push_back(x) #define pf pop_front(); #define last(c) c[c.size()-1] #define f first #define s second #define pi pair<int, int> #define mp(x,y) make_pair(x, y) const ll mod = 1000000007; const double ppi = acos(0) * 2; const int maxn = 2e5; const int inf = INT_MAX; const ll linf = LLONG_MAX; const ll mmod = 998244353; int dp[1000][50001]; void solve() { int n; cin>>n; vii(a,n); vector<int> pr = ___makeprefsum(a); dp[0][a[0]]=0; for (int i=1; i<n; ++i) { for (int j=1; j<=(pr[n]+1)/2; ++j) { if (j==a[i]) {dp[i][j]=i; continue;} dp[i][j]=dp[i-1][j]; if (j-a[i]>=0) dp[i][j]=max(dp[i][j],dp[i-1][j-a[i]]); } } vector<int> ans; for (int k=2; k<=n; ++k) { int foo=1; for (int i=0; i+k<=n; ++i) { int s = pr[i+k]-pr[i]; if (s%2) {foo=0; break;} if (dp[i+k-1][s/2]<i) {foo=0; break;} } if (foo) ans.pb(k); } cout<<ans.size()<<' '; forn(i,ans.size()) cout<<ans[i]<<' '; cout<<'\n'; dp[0][a[0]]=-1; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //init_primes(); forn(i,5e4+1) dp[0][i]=-1; int t=1; cin>>t; while(t--) solve(); paiu moment }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2972 KB | Output is correct |
2 | Correct | 33 ms | 7500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 107 ms | 27640 KB | Output is correct |
2 | Correct | 293 ms | 61584 KB | Output is correct |
3 | Correct | 325 ms | 78348 KB | Output is correct |
4 | Correct | 579 ms | 131020 KB | Output is correct |
5 | Correct | 1346 ms | 320776 KB | Output is correct |
6 | Correct | 1901 ms | 385624 KB | Output is correct |
7 | Correct | 1750 ms | 391396 KB | Output is correct |