Submission #1280682

#TimeUsernameProblemLanguageResultExecution timeMemory
1280682syanvuKpart (eJOI21_kpart)C++20
30 / 100
757 ms110680 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma optimize("g", on) #pragma GCC optimize("03") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") // #define int long long // #define ull unsigned long long #define all(x) x.begin(),x.end() #define F first #define S second using namespace std; // using namespace __gnu_pbds; // #define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> const int LG = 17,N = 1e3 + 1, MX = 5e4 + 1,inf = 1e9 + 1, MOD = 1e9 + 7; const double eps = 1e-9; int T = 1; int dp[N][MX]; void solve() { int n; cin>>n; int a[n+1]; int pref[n+1]={}; for(int i=1;i<=n;i++){ cin>>a[i]; pref[i] = pref[i-1] + a[i]; } for(int i = 1; i <= n; i++){ for(int j=0;j<=pref[n];j++){ dp[i][j] = 0; } } for(int i=1;i<=n;i++){ for(int j=1;j<=pref[n];j++){ dp[i][j] = max(dp[i][j],dp[i-1][j]); if(a[i] == j) dp[i][j] = i; if(j-a[i]>0) dp[i][j] = max(dp[i][j], dp[i-1][j-a[i]]); } } vector<int> v; for(int k = 2; k <= n; k++){ bool ch=0; for(int i = k; i <= n; i++){ int sum = pref[i] - pref[i-k]; if(sum%2 != 0 || dp[i][sum/2] < i - k + 1){ ch = 1; break; } } if(!ch) v.push_back(k); } cout << v.size() << ' '; for(int k : v) cout << k << ' '; cout << '\n'; } /* 1 2 3 4 5 5 4 3 2 1 */ signed main() { SS int t = 1; if(T) cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...