Submission #538326

# Submission time Handle Problem Language Result Execution time Memory
538326 2022-03-16T15:27:48 Z siewjh Popeala (CEOI16_popeala) C++17
100 / 100
531 ms 9664 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 2e9 + 5;
ll pref[20'005];
bool ac[55][20'005];
ll dp[55][20'005];
signed 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++){
        ll 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 time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1124 KB Output is correct
2 Correct 12 ms 1108 KB Output is correct
3 Correct 13 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 1884 KB Output is correct
2 Correct 86 ms 2260 KB Output is correct
3 Correct 117 ms 2708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 13 ms 1124 KB Output is correct
4 Correct 12 ms 1108 KB Output is correct
5 Correct 13 ms 1128 KB Output is correct
6 Correct 53 ms 1884 KB Output is correct
7 Correct 86 ms 2260 KB Output is correct
8 Correct 117 ms 2708 KB Output is correct
9 Correct 163 ms 3868 KB Output is correct
10 Correct 203 ms 4788 KB Output is correct
11 Correct 514 ms 9620 KB Output is correct
12 Correct 508 ms 9656 KB Output is correct
13 Correct 482 ms 9660 KB Output is correct
14 Correct 516 ms 9664 KB Output is correct
15 Correct 531 ms 9660 KB Output is correct