Submission #334202

#TimeUsernameProblemLanguageResultExecution timeMemory
334202BeanZBigger segments (IZhO19_segments)C++14
37 / 100
90 ms71020 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 3e3 + 5; long long mod = 1e9 + 7; const int lim = 5e5; const int lg = 20; const int base = 311; const long double eps = 1e-6; ll a[N], sum[N], dp[N][N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("test.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i]; for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ dp[i][j] = -1e9; } } for (int i = 1; i <= n; i++) dp[1][i] = 1; for (int i = 2; i <= n; i++){ ll best = -1e9; ll l = i - 1; for (int j = i; j <= n; j++){ ll tot = sum[j] - sum[i - 1]; while (l > 0 && (sum[i - 1] - sum[l - 1]) <= tot){ best = max(best, dp[l][i - 1]); l--; } dp[i][j] = best + 1; } } //cout << dp[1][1] << " " << dp[2][3] << endl; ll ans = 0; for (int i = 1; i <= n; i++){ ans = max(ans, dp[i][n]); } cout << ans; } /* Ans: Out: */

Compilation message (stderr)

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