#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
void ckmax(int& a, int b){
a = max(a, b);
}
void ckmin(ll& a, ll b){
a = min(a, b);
}
void ckmin(pair<ll, int>& a, pair<ll, int> b){
a = min(a, b);
}
const ll INF = 1e18;
int N, T, S;
int points[20005];
ll point_sum[20005];
bool solved[55][20005];
pair<ll, int> dp[55][20005];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> N >> T >> S;
for(int i = 1; i <= T; i++){
cin >> points[i];
}
for(int i = 1; i <= N; i++){
string s;
cin >> s;
for(int j = 1; j <= T; j++){
if(s[j-1] == '1'){
solved[i][j] = 1;
}
}
}
for(int j = 0; j <= S; j++){
for(int i = 0; i <= T; i++){
dp[j][i].f = INF;
}
}
for(int i = 1; i <= T; i++){
point_sum[i] = point_sum[i-1]+points[i];
}
dp[0][0] = mp(0, 0);
for(int i = 1; i <= T; i++){
bitset<55> bad;
for(int j = i-1; j >= 0; j--){
ll cur_points = 0;
for(int k = 1; k <= N; k++){
if(!solved[k][j+1]){
bad[k] = 1;
}
if(!bad[k]){
cur_points+=point_sum[i]-point_sum[j];
}
}
for(int k = 1; k <= S; k++){
ckmin(dp[k][i], mp(dp[k-1][j].f+cur_points, j));
}
}
}
//switch for loop order
for(int i = 0; i <= T; i++){
for(int j = 0; j <= S; j++){
if(j+1 <= S && dp[j][i].f < INF && dp[j+1][i].f < INF){
assert(dp[j][i].s <= dp[j+1][i].s);
}
// if(dp[j][i].f < INF){
// cout << i << " " << j << " " << dp[j][i].f << " " << dp[j][i].s << "\n";
// }
}
}
for(int j = 1; j <= S; j++){
cout << dp[j][T].f << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Runtime error |
4 ms |
972 KB |
Execution killed with signal 6 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
36 ms |
2216 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
584 ms |
5188 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Runtime error |
4 ms |
972 KB |
Execution killed with signal 6 |