Submission #536993

# Submission time Handle Problem Language Result Execution time Memory
536993 2022-03-14T09:04:23 Z ecx Popeala (CEOI16_popeala) C++17
17 / 100
2000 ms 1108 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> pv;
vector<int> pvpfix;
vector<vector<int> > rs;
vector<vector<int> > rspfix;
vector<vector<int> > mem;

int n;

int rc() {
    char c; cin >> c; return (c-'0');
}

int score(int l, int r) { // inclusive
    int sc = 0;
    int stw = pv[r] - pv[l-1];
    for (int i = 0; i < n; i++) {
        if ((rs[i][r] - rs[i][l-1]) == (r-l+1)) sc += stw;
    }
    return sc;
}

int dp(int tc, int st) { // questions are 1 to N, tc is inclusive
    if (mem[st][tc] > -1) return mem[st][tc];
    if (st == 1) return score(1, tc);
    int optimal = dp(tc-1, st-1) + score(tc, tc);
    for (int left = tc-1; left >= st; left--) {
        optimal = min(optimal, dp(left-1, st-1) + score(left, tc));
    }
    return mem[st][tc] = optimal;
}

int main() {

    int t, s; cin >> n >> t >> s;
    pv.assign(t+5, 0);
    rs.assign(n, vector<int>(t+5, 0));
    mem.assign(s+5, vector<int>(t+5, -1));

    for (int i = 1; i < t+1; i++) cin >> pv[i];
    for (int i = 1; i < t+1; i++) pv[i] += pv[i-1];

    for (int i = 0; i < n; i ++) {
        for (int j = 1; j < t+1; j++) rs[i][j] = rc();
        for (int j = 1; j < t+1; j++) rs[i][j] += rs[i][j-1];
    }

    for (int i = 1; i <= s; i++) {
        cout << dp(t, i) << endl;
    }

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 468 KB Output is correct
2 Correct 318 ms 468 KB Output is correct
3 Correct 308 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 302 ms 468 KB Output is correct
4 Correct 318 ms 468 KB Output is correct
5 Correct 308 ms 468 KB Output is correct
6 Execution timed out 2074 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -