Submission #538324

# Submission time Handle Problem Language Result Execution time Memory
538324 2022-03-16T15:26:35 Z siewjh Popeala (CEOI16_popeala) C++17
100 / 100
475 ms 9664 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 2e9 + 5;
int pref[20'005];
bool ac[55][20'005];
int 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++){
        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 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 12 ms 1108 KB Output is correct
2 Correct 11 ms 1116 KB Output is correct
3 Correct 13 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1876 KB Output is correct
2 Correct 74 ms 2260 KB Output is correct
3 Correct 96 ms 2644 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 12 ms 1108 KB Output is correct
4 Correct 11 ms 1116 KB Output is correct
5 Correct 13 ms 1108 KB Output is correct
6 Correct 50 ms 1876 KB Output is correct
7 Correct 74 ms 2260 KB Output is correct
8 Correct 96 ms 2644 KB Output is correct
9 Correct 150 ms 3868 KB Output is correct
10 Correct 200 ms 4692 KB Output is correct
11 Correct 466 ms 9632 KB Output is correct
12 Correct 467 ms 9664 KB Output is correct
13 Correct 468 ms 9660 KB Output is correct
14 Correct 471 ms 9660 KB Output is correct
15 Correct 475 ms 9660 KB Output is correct