#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 300001;
const ll INF = (1LL << 60);
const ll MOD = 998244353;
const ll BLOCK = 225;
const ll base = 31;
const ll nr_of_bits = 21;
int dp[20001][51];
int n, t, s;
int sum[20001];
int results[51][20001];
int last[51][20001];
void divide(int k, int l, int r, int optl, int optr) {
int mid = (l + r) / 2;
int opt = optl;
for(int i = optl; i <= min(mid, optr); i++) {
int scor = 0;
///aici pot sa mai optimizez
for(int j = 1; j <= n; j++) {
if(last[j][i - 1] == last[j][mid]) {
scor++;
}
}
scor *= (sum[mid] - sum[i - 1]);
if(dp[i - 1][k - 1] + scor < dp[mid][k]) {
dp[mid][k] = dp[i - 1][k - 1] + scor;
opt = i;
}
}
if(mid - 1 >= l)
divide(k, l, mid - 1, optl, opt);
if(mid + 1 <= r)
divide(k, mid + 1, r, opt, optr);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> t >> s;
for(int i = 1; i <= t; i++) {
cin >> sum[i];
sum[i] += sum[i - 1];
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= t; j++) {
last[i][j] = last[i][j - 1];
char c;
cin >> c;
results[i][j] = c - '0';
if(results[i][j] == 0)
last[i][j] = j;
}
}
for(int i = 0; i <= t; i++) {
for(int j = 0; j <= s; j++)
dp[i][j] = 2e9;
}
dp[0][0] = 0;
for(int i = 1; i <= s; i++)
divide(i, 1, t, 1, t);
for(int i = 1; i <= s; i++) {
cout << dp[t][i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
2072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |