Submission #537038

#TimeUsernameProblemLanguageResultExecution timeMemory
537038ecxPopeala (CEOI16_popeala)C++17
17 / 100
2080 ms1108 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...