Submission #1066064

#TimeUsernameProblemLanguageResultExecution timeMemory
1066064manhlinh1501Bigger segments (IZhO19_segments)C++17
0 / 100
1 ms2516 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 5e5 + 5; int N; int a[MAXN]; namespace subtask3 { const int MAXN = 3e3 + 5; int dp[MAXN][MAXN]; i64 prefix[MAXN]; void solution() { for(int i = 1; i <= N; i++) prefix[i] = prefix[i - 1] + a[i]; int ans = 0; for(int i = 1; i <= N; i++) { int cnt = 0; i64 cur = prefix[i]; for(int j = i; j <= N; j++) { cnt++; int z = j; while(z <= N and prefix[z] - prefix[j] < cur) z++; cur = prefix[z] - prefix[j]; j = z - 1; } ans = max(ans, cnt); } cout << ans; } } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i <= N; i++) cin >> a[i]; subtask3::solution(); return (0 ^ 0); } /** 4 2 3 1 7 **/ /** 5 6 2 3 9 13 **/ /** 3 3 1 2 **/

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...