이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |