Submission #538592

#TimeUsernameProblemLanguageResultExecution timeMemory
538592alextodoranPopeala (CEOI16_popeala)C++17
0 / 100
20 ms1772 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int T_MAX = 20000; const int N_MAX = 50; const int S_MAX = 50; int T, N, S; int points[T_MAX + 2]; bool solved[N_MAX + 2][T_MAX + 2]; int pref[T_MAX + 2]; int streak[T_MAX + 2][N_MAX + 2]; int subtaskSum (int l, int r) { int lo = 0, hi = N; while (lo < hi) { int mid = (lo + hi + 1) / 2; if (streak[l][mid] >= r) { lo = mid; } else { hi = mid - 1; } } return (pref[r] - pref[l - 1]) * lo; } int minSum[S_MAX + 2][T_MAX + 2]; void solve (int s, int rLo, int rHi, int lLo = 1, int lHi = T) { int r = (rLo + rHi) / 2; minSum[s][r] = INT_MAX; int bestl = lLo; for (int l = lLo; l <= min(lHi, r); l++) { if (minSum[s - 1][l - 1] < INT_MAX) { int sum = minSum[s - 1][l - 1] + subtaskSum(l, r); if (sum < minSum[s][r]) { bestl = l; minSum[s][r] = sum; } } } if (rLo < r) { solve(s, rLo, r - 1, lLo, bestl); } if (r < rHi) { solve(s, r + 1, rHi, bestl, lHi); } } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> T >> S; for (int t = 1; t <= T; t++) { cin >> points[t]; pref[t] = pref[t - 1] + points[t]; } for (int i = 1; i <= N; i++) { string str; cin >> str; for (int t = 1; t <= T; t++) { solved[i][t] = (str[t - 1] == '1'); } } for (int t = T; t >= 1; t--) { for (int i = 1; i <= N; i++) { streak[t][i] = (solved[i][t] == true ? streak[t + 1][i] + 1 : 0); } } for (int t = 1; t <= T; t++) { for (int i = 1; i <= N; i++) { streak[t][i] = t + streak[t][i] - 1; } sort(streak[t] + 1, streak[t] + N + 1, greater <int> ()); } for (int t = 1; t <= T; t++) { minSum[0][t] = INT_MAX; } for (int s = 1; s <= S; s++) { minSum[s][0] = INT_MAX; solve(s, 1, T); cout << minSum[s][T] << "\n"; } 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...