#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
bool solved[51][20001];
ll dp[20001][51];
int dpwith[20001][51];
int conssolved[51][20001]; //[x][y]=z means, the xth solved y-z+1,y-z+2,...,y tasks but not the y-z th
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,t,s;
cin >> n >> t >> s;
vi p(t+1);
for(int i = 1; i <= t; i++) {
cin >> p[i];
}
for(int i = 1; i <= n; i++) {
int lastnotsolv = 0;
for(int j = 1; j <= t; j++) {
char ch;
cin >> ch;
solved[i][j] = (ch == '1');
if(!solved[i][j]) {
lastnotsolv = j;
}
conssolved[i][j] = j-lastnotsolv;
}
}
int sum = 0;
for(int i = 1; i <= t; i++) {
sum+= p[i];
int solv = 0;
for(int j = 1; j <= n; j++) {
if(conssolved[j][i] == i) {
solv++;
}
}
dp[i][1] = solv*sum;
}
for(int i = 1; i <= t; i++) {
for(int j = 2; j <= s; j++) {
dp[i][j] = 2*MOD;
sum = 0;
vector<int> solves;
for(int st = 1; st <= n; st++) {
solves.push_back(conssolved[st][i]);
}
sort(solves.begin(),solves.end());
int ind = 0;
for(int currsiz = 1; currsiz <= i-j+1; currsiz++) {
while(ind < n && solves[ind] < currsiz) {
ind++;
}
sum+= p[i-currsiz+1];
if(dp[i-currsiz][j-1]+(n-ind)*sum < dp[i][j]) {
dp[i][j] = dp[i-currsiz][j-1]+(n-ind)*sum;
// dpwith[i][j] = currsiz;
}
if(dp[i][j] == dp[i][j-1]) {
break;
}
}
//cout << i << " " << j << " " << dp[i][j] << endl;
}
}
for(int i = 1; i <= s; i++) {
cout << dp[t][i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
416 KB |
Output is correct |
2 |
Correct |
4 ms |
820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
1252 KB |
Output is correct |
2 |
Correct |
73 ms |
1268 KB |
Output is correct |
3 |
Correct |
77 ms |
1268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
697 ms |
2336 KB |
Output is correct |
2 |
Correct |
1415 ms |
3020 KB |
Output is correct |
3 |
Execution timed out |
2052 ms |
3556 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
416 KB |
Output is correct |
2 |
Correct |
4 ms |
820 KB |
Output is correct |
3 |
Correct |
77 ms |
1252 KB |
Output is correct |
4 |
Correct |
73 ms |
1268 KB |
Output is correct |
5 |
Correct |
77 ms |
1268 KB |
Output is correct |
6 |
Correct |
697 ms |
2336 KB |
Output is correct |
7 |
Correct |
1415 ms |
3020 KB |
Output is correct |
8 |
Execution timed out |
2052 ms |
3556 KB |
Time limit exceeded |