#include <bits/stdc++.h>
using namespace std;
const int k_T = 2e4 + 3;
const int k_N = 50 + 3;
const int k_S = 50 + 3;
int n, t, s;
int points[k_T];
string results[k_N];
long long dp[k_S][k_T];
int sum[k_N];
bool counts[k_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t >> s;
for(int i = 0; i < t; ++i)
cin >> points[i];
for(int i = 0; i < n; ++i)
cin >> results[i];
for(int subtasks = 0; subtasks <= s; ++subtasks){
for(int pos = 0; pos <= t; ++pos){
long long &answer = dp[subtasks][pos];
if(!subtasks) answer = (pos == t) ? 0 : INT_MAX;
else if(pos == t) answer = INT_MAX;
else{
for(int i = 0; i < n; ++i){
sum[i] = 0;
counts[i] = 1;
}
answer = INT_MAX;
for(int i = pos; i < t; ++i){
int add = 0;
for(int j = 0; j < n; ++j){
sum[j] += points[i];
if(results[j][i] == '0')
counts[j] = 0;
if(counts[j])
add += sum[j];
}
answer = min(add + dp[subtasks - 1][i + 1], answer);
}
}
//cout << subtasks << " " << pos << " = " << answer << endl;
}
}
for(int subtasks = 1; subtasks <= s; ++subtasks)
cout << dp[subtasks][0] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
750 ms |
760 KB |
Output is correct |
2 |
Correct |
751 ms |
888 KB |
Output is correct |
3 |
Correct |
783 ms |
964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2085 ms |
1028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
750 ms |
760 KB |
Output is correct |
4 |
Correct |
751 ms |
888 KB |
Output is correct |
5 |
Correct |
783 ms |
964 KB |
Output is correct |
6 |
Execution timed out |
2085 ms |
1028 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |