Submission #483751

#TimeUsernameProblemLanguageResultExecution timeMemory
483751minhcoolPopeala (CEOI16_popeala)C++17
0 / 100
19 ms2060 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, r, l) for(int i = r; i >= l; i--) #define eb emplace_back typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 2e4 + 5, MAXN = 1e7 + 5; const long long oo = 1e9 + 7, mod = 1e9 + 7; int t, n, s, a[N]; int pref[N]; int nxt[55][N]; vector<int> vc[N]; int f[N], g[N]; int eval(int l, int r){ int x = pref[r] - pref[l - 1]; //cout << l << " " << r << " " << x * (upper_bound(vc[l].begin(), vc[l].end(), r) - vc[l].begin()) << "\n"; return x * (upper_bound(vc[l].begin(), vc[l].end(), r) - vc[l].begin()); } void dnc(int l, int r, int optl, int optr){ if(optl > optr) return; if(l > r) return; if(optl == optr){ //cout << l << " " << r << " " << optl << "\n"; for(int i = l; i <= r; i++) g[i] = f[optl] + eval(optl + 1, i); return; } int mid = (l + r) >> 1; ii mx = {-oo, -oo}; for(int i = optl; i <= min(mid - 1, optr); i++){ mx = max(mx, {f[i] + eval(i + 1, mid), i}); } //cout << mid << " " << mx.se << "\n"; g[mid] = mx.fi; dnc(l, mid - 1, optl, mx.se); dnc(mid + 1, r, mx.se, optr); } void process(){ cin >> n >> t >> s; for(int i = 1; i <= t; i++) cin >> a[i]; for(int i = 1; i <= t; i++) pref[i] = (pref[i - 1] + a[i]); for(int i = 1; i <= n; i++){ for(int j = 1; j <= t; j++){ char x; cin >> x; if(x == '0') nxt[i][j] = j; else nxt[i][j] = oo; } vc[t].pb(nxt[i][t]); for(int j = t - 1; j >= 1; j--){ nxt[i][j] = min(nxt[i][j], nxt[i][j + 1]); vc[j].pb(nxt[i][j]); } for(int j = 1; j <= t; j++){ //cout << i << " " << j << " " << nxt[i][j] << "\n"; } } for(int i = 1; i <= t; i++) sort(vc[i].begin(), vc[i].end()); s--; g[0] = -oo; for(int i = 1; i <= t; i++){ g[i] = eval(1, i); //cout << i << " " << g[i] << "\n"; } cout << pref[t] * n - g[t] << "\n"; for(int i = 1; i <= s; i++){ for(int j = 0; j <= t; j++){ f[j] = g[j]; g[j] = -oo; } dnc(1, t, 0, t - 1); cout << pref[t] * n - g[t] << "\n"; } } signed main(){ ios_base::sync_with_stdio(0); #ifdef nqm freopen("input.inp", "r", stdin); freopen("output.out", "w", stdout); #endif #ifndef nqm #endif process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...