Submission #420518

#TimeUsernameProblemLanguageResultExecution timeMemory
420518JvThunderCigle (COI21_cigle)C++14
9 / 100
1067 ms332 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fir first #define sec second typedef long long ll; using namespace std; int n; vector<int> v; void solve() { cin >> n; for(int i=0;i<n;i++) { int tmp; cin >> tmp; v.pb(tmp); } int mxcnt = 0; for(int mask=0;mask<(1<<n);mask++) { int cnt = 0; set<int> prv; set<int> curr; int pos = 0; int layer = 0; bool impos = false; for(int j=1;j<n;j++) { int x1 = 0,x2 = 0; if((1<<j)&mask) x1 = 1; if((1<<(j-1))&mask) x2 = 1; if(x1==1 && x2==1) impos = true; } if(impos) continue; for(int j=0;j<n;j++) { if((1<<j)&mask) { layer++; prv.clear(); prv = curr; curr.clear(); } int sign = 1; if(layer%2) sign *= -1; pos += sign*v[j]; if(prv.find(pos)!=prv.end() && ((1<<j+1)&mask)==0 && j!=n-1) cnt++; curr.insert(pos); } mxcnt = max(mxcnt,cnt); } cout << mxcnt << endl; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc=1; //cin>>tc; for(int i=1;i<=tc;i++) solve(); return 0; }

Compilation message (stderr)

cigle.cpp: In function 'void solve()':
cigle.cpp:54:50: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   54 |             if(prv.find(pos)!=prv.end() && ((1<<j+1)&mask)==0 && j!=n-1) cnt++;
      |                                                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...