Submission #342537

#TimeUsernameProblemLanguageResultExecution timeMemory
342537NurstanDuisengalievBigger segments (IZhO19_segments)C++14
37 / 100
223 ms72172 KiB
// Nurstan Duisengaliev // не, не надо меня узнавать /*#pragma GCC target ("avx2") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("O3")*/ #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define ll long long #define all(x) x.begin(), x.end() #define in insert #define mp make_pair #define F first #define S second #define ppf pop_front #define pb push_back #define ppb pop_back #define pf push_front #define pii pair <int, int> #define pll pair <ll, ll> #define boost() ios_base::sync_with_stdio(0), cin.tie(0) #define sz(x) (int)x.size() using namespace std; //using namespace __gnu_pbds; //template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 3005; const int mod = (int)1e9 + 7; const ll INF = (ll)1e18 + 1; int n; ll a[N], pref[N]; int dp[N][N]; void solve () { cin >> n; for (int i = 1; i <= n; i ++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; for (int j = 1; j <= n; j ++) dp[i][j] = -1; dp[i][i] = 1; } for (int i = 1; i < n; i ++) { for (int j = 1; j <= i; j ++) { ll x = pref[i] - pref[i - j]; if (dp[i][j] != -1) { dp[i + 1][j + 1] = max (dp[i + 1][j + 1], dp[i][j]); int pos = -1; int l = i + 1, r = n; while (l <= r) { int mid = l + r >> 1; if (pref[mid] - pref[i] >= x) { r = mid - 1; pos = mid; } else { l = mid + 1; } } if (pos != -1) dp[pos][pos - i] = max (dp[pos][pos - i], dp[i][j] + 1); } } } int maxi = 0; for (int i = 1; i <= n; i ++) { maxi = max (maxi, dp[n][i]); } cout << maxi; } main () { // freopen (".in", "r", stdin); // freopen (".out", "w", stdout); boost (); int TT = 1; // cin >> TT; while (TT --) { solve (); } return 0; }

Compilation message (stderr)

segments.cpp: In function 'void solve()':
segments.cpp:55:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |      int mid = l + r >> 1;
      |                ~~^~~
segments.cpp: At global scope:
segments.cpp:75:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main () {
      |       ^
#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...