Submission #1161740

#TimeUsernameProblemLanguageResultExecution timeMemory
1161740strelok1337Kpart (eJOI21_kpart)C++20
30 / 100
2093 ms4404 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pf push_front #define F first #define S second #define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define all(a) a.begin(),a.end() const int N=1e3+10; const ll inf = 1e18 + 1337; const int mod=1e9+7; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; int a[N],sum[N],ans[N],dp[(int)1e5][10]; int main() { //freopen("bank.in","r",stdin); //freopen("bank.out","w",stdout); IShowSpeed ll tt=1; cin>>tt; while(tt--) { ll n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; sum[i] = sum[i-1] + a[i]; ans[i] = 1; } for(int i=0;i<=1e5;i++) dp[i][0] = dp[i][1] = 0; for(int i=1;i<=n;i++) { dp[0][0] = i; for(int j=0;j<=5e4;j++) { if(j + a[i] > (int)5e4) break; dp[j+a[i]][1] = max(dp[j][0],dp[j+a[i]][1]); dp[j][1] = max(dp[j][0],dp[j][1]); } for(int l=1;l<=i;l++) { int x = sum[i] - sum[l-1]; if(dp[x >> 1][1] < l || x % 2 == 1) ans[i - l + 1] = 0; } for(int j=0;j<=5e4;j++) { dp[j][0] = dp[j][1]; dp[j][1] = 0; } } vector<ll>res; for(int i=1;i<=n;i++) { if(ans[i]) res.pb(i); } cout<<res.size()<<" "; for(ll x: res) cout<<x<<" "; cout<<"\n"; } } /* 1 2 2 2 3 1 */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:61: warning: iteration 100000 invokes undefined behavior [-Waggressive-loop-optimizations]
   33 |                 for(int i=0;i<=1e5;i++) dp[i][0] = dp[i][1] = 0;
      |                                                    ~~~~~~~~~^~~
Main.cpp:33:30: note: within this loop
   33 |                 for(int i=0;i<=1e5;i++) dp[i][0] = dp[i][1] = 0;
      |                             ~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...