Submission #433244

#TimeUsernameProblemLanguageResultExecution timeMemory
433244cpp219Bigger segments (IZhO19_segments)C++14
0 / 100
1 ms332 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 5e5 + 9; const ll mod = 1e9 + 7; const ll base = 31; typedef pair<ll,ll> LL; ll n,a[N],pre[N],dp[N],best[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n; for (ll i = 1;i <= n;i++) cin>>a[i],pre[i] = pre[i - 1] + a[i]; for (ll i = 1;i <= n;i++){ best[i] = max(best[i],best[i - 1]); dp[i] = dp[best[i]] + 1; ll cur = pre[i] - pre[best[i]]; ll nxt = lower_bound(pre + 1,pre + n + 1,cur) - pre; best[nxt] = max(best[nxt],i); } cout<<dp[n]; }

Compilation message (stderr)

segments.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
segments.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
segments.cpp: In function 'int main()':
segments.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...