Submission #1097131

#TimeUsernameProblemLanguageResultExecution timeMemory
1097131hgmhc도넛 (JOI14_ho_t3)C++17
100 / 100
187 ms3728 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+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:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:41:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         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...