Submission #344581

#TimeUsernameProblemLanguageResultExecution timeMemory
344581NurlykhanBigger segments (IZhO19_segments)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)500 + 10; const int mod = (int)1e9 + 7; int n; int a[N]; ll pref[N]; ll get_sum(int l, int r) { return pref[r + 1] - pref[l]; } int dp[N][N]; int main() { freopen("in.txt", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pref[i] = pref[i - 1] + a[i]; printf("%d ", pref[i]); } printf("\n"); for (int r0 = 0; r0 <= n; r0++) { for (int r1 = r0 + 1; r1 <= n; r1++) { dp[r0][r1] = -mod; } dp[0][r0] = 0; } for (int r0 = 0; r0 <= n; r0++) { for (int r1 = r0 + 1; r1 <= n; r1++) { for (int r2 = r1 + 1; r2 <= n; r2++) { if (2 * pref[r1] - pref[r0] <= pref[r2]) { dp[r1][r2] = max(dp[r1][r2], dp[r0][r1] + 1); } } } } int ans = 0; for (int r0 = 0; r0 <= n; r0++) ans = max(ans, dp[r0][n]); cout << ans + 1; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:26:18: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   26 |         printf("%d ", pref[i]);
      |                 ~^    ~~~~~~~
      |                  |          |
      |                  int        long long int
      |                 %lld
segments.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
segments.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segments.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         scanf("%d", &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...
#Verdict Execution timeMemoryGrader output
Fetching results...