답안 #537038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537038 2022-03-14T09:57:46 Z ecx 조교 (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() {

    ios::sync_with_stdio(0);cin.tie(0);

    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;
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 520 KB Output is correct
2 Correct 312 ms 532 KB Output is correct
3 Correct 292 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2080 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 315 ms 520 KB Output is correct
4 Correct 312 ms 532 KB Output is correct
5 Correct 292 ms 468 KB Output is correct
6 Execution timed out 2080 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -