Submission #1097134

#TimeUsernameProblemLanguageResultExecution timeMemory
1097134hgmhc도넛 (JOI14_ho_t3)C++17
100 / 100
171 ms2760 KiB
#include <bits/stdc++.h> #define rep(i,a,b) for (auto i = (a); i <= (b); ++i) using namespace std; using ll = long long; const int N = 1e5+3; int n, a[2*N]; ll p[2*N], S; bool valid(ll l) { int s = 1, e = 0; ll sum = 0; while (s <= n and e < n+n) { if (sum < l) { sum += a[++e]; } else { int x = e+1, y = n+n, m; while (x <= y) { m = (x+y)/2; if (p[m]-p[e] >= sum) y = m-1; else x = m+1; } if (p[x]-p[e] > 0 and S-(p[x]-p[e])-sum >= sum) { return true; } sum -= a[s++]; } } return false; } int main() { scanf("%d", &n); rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i], a[i+n] = a[i]; S = p[n]; rep(i,n+1,n+n) p[i] = p[i-1]+a[i]; ll x = 0, y = 1e15, m; while (x <= y) { m = (x+y)/2; if (valid(m)) x = m+1; else y = m-1; } printf("%lld", y); }

Compilation message (stderr)

2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:33:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i], a[i+n] = a[i];
      |                ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...