Submission #519863

#TimeUsernameProblemLanguageResultExecution timeMemory
519863Hacv16Nizin (COCI16_nizin)C++17
100 / 100
70 ms6256 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAX = 2e6 + 15; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; #define pb push_back #define sz(x) (int) x.size() #define fr first #define sc second #define mp make_pair #define all(x) x.begin(), x.end() #define dbg(x) cout << #x << ": " << "[ " << x << " ]\n" int n, v[MAX], ans; void setIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } int main(){ setIO(); cin >> n; for(int i = 1; i <= n; i++){ cin >> v[i]; } int l = 1, r = n; int sl = 0, sr = 0; while(l < r){ sl += v[l], sr += v[r]; v[l] = 0, v[r] = 0; //avoid double-counting if(sl == sr){ l++, r--; sl = sr = 0; }else if(sl > sr){ r--, ans++; }else{ l++, ans++; } } cout << ans << '\n'; return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * brute force to find pattern? * sort? * graph? * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#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...
#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...