This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
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... |