제출 #1066012

#제출 시각아이디문제언어결과실행 시간메모리
1066012manhlinh1501Bigger segments (IZhO19_segments)C++17
37 / 100
74 ms98896 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 5e5 + 5; int N; int a[MAXN]; namespace subtask { 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]; memset(dp, -0x3f, sizeof dp); for(int i = 1; i <= N; i++) dp[i][1] = 1; for(int i = 1; i <= N; i++) { for(int z = 1; z <= i; z++) { for(int j = z; j <= i; j++) { if(prefix[i] + prefix[z - 1] >= 2 * prefix[j - 1]) dp[i][j] = max(dp[i][j], dp[j - 1][z] + (i != j or j != z)); else break; } } } int ans = 0; for(int i = 1; i <= N; i++) ans = max(ans, dp[N][i]); cout << ans << "\n"; } } 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]; memset(dp, -0x3f, sizeof dp); for(int i = 1; i <= N; i++) dp[i][1] = 1; for(int i = 1; i <= N; i++) { int j = 1; for(int z = 1; z <= i; z++) { j = max(j, z); while(j < i and prefix[i] + prefix[z - 1] >= 2 * prefix[j]) j++; if(prefix[i] + prefix[z - 1] >= 2 * prefix[j - 1]) dp[i][j] = max(dp[i][j], dp[j - 1][z] + (i != j or j != z)); } } int ans = 0; for(int i = 1; i <= N; i++) ans = max(ans, dp[N][i]); cout << ans << "\n"; } } 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 **/

컴파일 시 표준 에러 (stderr) 메시지

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