#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;
ll 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] = inf;
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, ll 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);
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[j][i] = inf;
for(int turn = 1; turn <= s; ++turn){
build();
for(int i = 1; i <= n; ++i) last[i] = 0;
if(turn == 1) upd(0, 0, -inf);
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] - inf);
}
}
for(int i = 1; i <= s; ++i) cout << dp[t][i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
382 ms |
932 KB |
Output is correct |
2 |
Correct |
383 ms |
932 KB |
Output is correct |
3 |
Correct |
391 ms |
936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2064 ms |
1868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
588 KB |
Output is correct |
3 |
Correct |
382 ms |
932 KB |
Output is correct |
4 |
Correct |
383 ms |
932 KB |
Output is correct |
5 |
Correct |
391 ms |
936 KB |
Output is correct |
6 |
Execution timed out |
2064 ms |
1868 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |