Submission #482023

#TimeUsernameProblemLanguageResultExecution timeMemory
482023ak2006Bigger segments (IZhO19_segments)C++14
13 / 100
1 ms316 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pii = pair<int,int>; using pll = pair<ll,ll>; using vpii = vector<pii>; using vpll = vector<pll>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void setIO() { fast; } int main() { setIO(); int n; cin>>n; vi a(n + 1),p(n + 1),best(n + 1),dp(n + 1); for (int i = 1;i<=n;i++){cin>>a[i];p[i] = p[i - 1] + a[i];} int ans = 1; for (int i = 1;i<=n;i++){ best[i] = max(best[i], best[i - 1]); dp[i] = dp[best[i]] + 1; int pos = lower_bound(p.begin() + 1,p.end(),2 * p[i] - p[best[i]]) - p.begin(); best[pos] = max(best[pos],i); } cout<<dp[n]; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:28:9: warning: unused variable 'ans' [-Wunused-variable]
   28 |     int ans = 1;
      |         ^~~
#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...