Submission #761663

#TimeUsernameProblemLanguageResultExecution timeMemory
761663hgmhc도넛 (JOI14_ho_t3)C++17
100 / 100
187 ms2696 KiB
#include <bits/stdc++.h> #define rep(i,a,b) for (auto i = (a); i <= (b); ++i) #define Mup(x,y) x = max(x,y) #define mup(x,y) x = min(x,y) #define all(x) begin(x),end(x) #define per(i,a,b) for (auto i = (b); i >= (a); --i) using namespace std; using ll = long long; using ii = pair<int,int>; #define dbg(...) fprintf(stderr,__VA_ARGS__) 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+s) { 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) { // dbg("%lld: [%d,%d]\n", sum,s,e); // dbg("%lld: [%d,%d]\n", p[x]-p[e],e+1,x); // dbg("%lld: [%d,%d]\n", S-(p[x]-p[e])-sum,x+1,s-1); 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:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:44:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     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...