#include <bits/stdc++.h>
#define int long long
using namespace std;
int N, T, S;
int points[20005];
int prefixpoints[20005];
bool solves[20005][52];
int presolve[20005][52];
int DP[52][20005];
int INF = 2e9 + 5;
int score(int i, int j){
//value of zero indexed [i, j] inclusive interval
int val = prefixpoints[j] - prefixpoints[i - 1];
int res = 0;
for (int x = 1; x <= N; x++){
if (presolve[x][j] - presolve[x][i - 1] == j - i + 1){
res += val;
}
}
return res;
}
main(){
cin >> N >> T >> S;
for (int i = 1; i <= T; i++){
cin >> points[i];
}
prefixpoints[0] = 0;
for (int i = 1; i <= T; i++){
prefixpoints[i] = prefixpoints[i - 1] + points[i];
}
for (int i = 1; i <= N; i++){
string s; cin >> s;
for (int j = 1; j <= T; j++){
solves[i][j] = (s[j - 1] - '0');
}
presolve[i][0] = 0;
for (int j = 1; j <= T; j++){
presolve[i][j] = solves[i][j] + presolve[i][j - 1];
}
}
for (int j = 1; j <= T; j++){
DP[1][j] = score(1, j);
}
cout << DP[1][T] << endl;
for (int i = 2; i <= S; i++){
for (int j = i; j <= T; j++){
DP[i][j] = INF;
for (int k = i; k <= j; k++){
DP[i][j] = min(DP[i][j], DP[i - 1][k - 1] + score(k, j));
}
}
cout << DP[i][T] << endl;
}
}
Compilation message
popeala.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
381 ms |
924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2059 ms |
1028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Incorrect |
381 ms |
924 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |