Submission #1109239

#TimeUsernameProblemLanguageResultExecution timeMemory
1109239cpptowinKpart (eJOI21_kpart)C++17
100 / 100
737 ms4692 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; #define int long long #define inf (int)1e18 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1LL) #define offbit(i,j) (i^(1LL<<j)) #define onbit(i,j) (i|(1LL<<j)) #define vi vector<int> #define all(x) x.begin(),x.end() #define ss(x) (int)x.size() #define all(x) x.begin(),x.end() #define UNIQUE(v) v.erase(unique(all(v)),v.end()) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; const int mod = 1e9 + 7; const int nsqrt = 450; int n,a[maxn],pos[maxn],p[maxn]; void solve() { cin >> n; vi candidate; fo(i,1,n) { cin >> a[i],candidate.pb(i); p[i] = p[i - 1] + a[i]; } fo(i,1,50000) pos[i] = -1; fo(i,1,n) { vi newcandidate; pos[0] = i; fod(j,50000,a[i]) maximize(pos[j],pos[j - a[i]]); for(int it : candidate) { if(it > i) { newcandidate.pb(it); continue; } int val = p[i] - p[i - it]; if(val & 1) continue; if(pos[val / 2] > i - it) newcandidate.pb(it); } candidate = newcandidate; } cout << ss(candidate) << ' '; for(int it : candidate) cout << it << ' ';en; } main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while(T--) solve(); }

Compilation message (stderr)

Main.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...