#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 10007;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 1e3;
int n, t, s, a[M], seg[4 * M], lazy[4 * M], dp[M][55], last[55], pref[M];
string win[M];
void build(int node = 1, int l = 0, int r = t){
lazy[node] = 0;
if(l == r){
seg[node] = 2e9;
return;
}
int mid = (l + r) / 2;
build(2 * node, l, mid);
build(2 * node + 1, mid + 1, r);
seg[node] = min(seg[2 * node], seg[2 * node + 1]);
return;
}
void push(int node, int l, int r){
if(lazy[node] != 0){
seg[node] += lazy[node];
if(l != r){
lazy[2 * node] += lazy[node];
lazy[2 * node + 1] += lazy[node];
}
lazy[node] = 0;
}
return;
}
void upd(int st, int en, int v, int node = 1, int l = 0, int r = t){
push(node, l, r);
if(l > en || r < st) return;
if(l >= st && r <= en){
lazy[node] += v;
push(node, l, r);
return;
}
int mid = (l + r) / 2;
upd(st, en, v, 2 * node, l, mid);
upd(st, en, v, 2 * node + 1, mid + 1, r);
seg[node] = min(seg[2 * node], seg[2 * node + 1]);
return;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//ifstream cin ("match.in");
//ofstream cout ("match.out");
cin >> n >> t >> s;
for(int i = 1; i <= t; ++i) cin >> a[i], pref[i] = pref[i - 1] + a[i];
for(int i = 1; i <= n; ++i) cin >> win[i];
for(int i = 0; i <= s; ++i) for(int j = 0; j <= t; ++j) dp[i][j] = 2e9;
dp[0][0] = 0;
for(int turn = 1; turn <= s; ++turn){
build();
for(int i = 1; i <= n; ++i) last[i] = -1;
if(turn == 1) upd(0, 0, -2e9);
for(int i = 1; i <= t; ++i){
for(int j = 1; j <= n; ++j){
if(win[j][i - 1] == '1'){
if(last[j] < i) upd(last[j], i - 1, a[i]);
}
else{
for(int k = last[j] + 1; k < i; ++k) upd(last[j], k - 1, -a[k]);
last[j] = i;
}
}
dp[i][turn] = seg[1];
upd(i, i, dp[i][turn - 1] - 2e9);
}
}
for(int i = 1; i <= s; ++i) cout << dp[t][i] << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Incorrect |
4 ms |
588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
432 ms |
780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
1300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Incorrect |
4 ms |
588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |