Submission #538321

#TimeUsernameProblemLanguageResultExecution timeMemory
538321siewjhPopeala (CEOI16_popeala)C++17
26 / 100
598 ms5504 KiB
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int pref[20'005]; bool ac[55][20'005]; int dp[55][20'005]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ppl, cases, grp; cin >> ppl >> cases >> grp; pref[0] = 0; for (int i = 1; i <= cases; i++) { cin >> pref[i]; pref[i] += pref[i - 1]; } for (int i = 1; i <= ppl; i++){ string str; cin >> str; for (int j = 1; j <= cases; j++) ac[i][j] = (str[j - 1] == '1'); } for (int i = 0; i <= grp; i++) for (int j = 0; j <= cases; j++) dp[i][j] = inf; dp[0][0] = 0; for (int i = 1; i <= grp; i++){ int best[55], last[55], fc[20'005]; memset(best, 0, sizeof(best)); memset(last, 0, sizeof(last)); for (int j = 0; j <= cases; j++) fc[j] = ppl; for (int j = 1; j <= cases; j++){ if (dp[i - 1][best[ppl]] + (pref[j] - pref[best[ppl]]) * fc[best[ppl] + 1] > dp[i - 1][j - 1] + (pref[j] - pref[j - 1]) * ppl) best[ppl] = j - 1; for (int p = 1; p <= ppl; p++){ if (ac[p][j]) continue; for (int k = last[p] + 1; k <= j; k++) best[fc[k]] = 0; for (int k = last[p] + 1; k <= j; k++){ fc[k]--; if (dp[i - 1][best[fc[k]]] + (pref[j] - pref[best[fc[k]]]) * fc[k] > dp[i - 1][k - 1] + (pref[j] - pref[k - 1]) * fc[k]) best[fc[k]] = k - 1; } last[p] = j; } if (j < i) continue; for (int p = 0; p <= ppl; p++) dp[i][j] = min(dp[i][j], dp[i - 1][best[p]] + (pref[j] - pref[best[p]]) * fc[best[p] + 1]); } cout << dp[i][cases] << '\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...