제출 #938119

#제출 시각아이디문제언어결과실행 시간메모리
938119sysiaBigger segments (IZhO19_segments)C++17
0 / 100
0 ms452 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 50; const int mod = 998244353; struct Tree{ vector<int>tab; int size = 1; Tree(int n){ while (size < n) size*=2; tab.assign(2*size, 0); } void update(int x, int v){ x += size; tab[x] = max(tab[x], v); while (x){ x/=2; tab[x] = max(tab[2*x], tab[2*x+1]); } } int query(int l, int r){ int ans = 0; for (l += size-1, r += size+1; r-l>1; l/=2, r/=2){ if (!(l&1)) ans = max(ans, tab[l+1]); if (r&1) ans = max(ans, tab[r-1]); } return ans; } }; void solve(){ int n; cin >> n; vector<int>a(n+1), pref(n+1); for (int i = 1; i<=n; i++){ cin >> a[i]; pref[i] = pref[i-1] + a[i]; } //dp[i][wynik] = min suma vector dp(n+1, vector<int>(K+1, oo)); for (int i = 1; i<=n; i++) dp[i][1] = pref[i]; for (int j = 1; j<K; j++){ for (int i = j; i<=n; i++){ if (dp[i][j] == oo) continue; //dwa razy wieksza suma prefiksowa int p = (int)(lower_bound(pref.begin(), pref.end(), dp[i][j] + pref[i])-pref.begin()); p = max(p, i+1); if (p < (int)pref.size()){ dp[p][j+1] = min(dp[p][j+1], pref[p] - pref[i]); } // debug(i, j, dp[i][j]); } } int ans = 1; for (int j = 1; j<=K; j++){ for (int i = 1; i<=n; i++){ if (dp[i][j] != oo){ ans = j; break; } } } cout << ans << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#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...