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;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, t, s;
cin >> n >> t >> s;
int dp[s][t], pts[t], sm = 0, tmp;
string score[n];
for(int i = 0; i < t; i++) cin >> pts[i];
for(int i = 0; i < n; i++) cin >> score[i];
bool died[n];
memset(died, 0, sizeof(died));
for(int i = 0; i < t; i++) {
for(int j = 0; j < n; j++) if(score[j][i] == '0') died[j] = 1;
dp[0][i] = 0; sm += pts[i];
for(int j = 0; j < n; j++) if(!died[j]) dp[0][i] += sm;
}
for(int i = 1; i < s; i++) {
dp[i][i] = dp[i-1][i-1];
for(int j = 0; j < n; j++) if(score[j][i] == '1') dp[i][i] += pts[i];
}
for(int i = 1; i < s; i++) {
for(int j = i+1; j < t; j++) {
dp[i][j] = 2e9;
memset(died, 0, sizeof(died));
tmp = 0; sm = 0;
for(int k = j; k >= i; k--) {
for(int l = 0; l < n; l++) if(score[l][k] == '0') died[l] = 1;
sm += pts[k]; tmp = 0;
for(int l = 0; l < n; l++) if(!died[l]) tmp += sm;
dp[i][j] = min(dp[i][j], dp[i-1][k-1] + tmp);
}
}
}
for(int i = 0; i < s; i++) cout << dp[i][t-1] << '\n';
}
# | 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... |