# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52917 | 2018-06-27T07:24:16 Z | 0^0(#1376) | Popeala (CEOI16_popeala) | C++11 | 2000 ms | 15488 KB |
#include <bits/stdc++.h> using namespace std; int n, t, s; const int inf = 2e9 + 5; struct SGT { int tree[1 << 16]; int sz = 1 << 15; void update(int idx, int val) { idx += sz; tree[idx] = val; idx /= 2; while (idx) { tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]); idx /= 2; } } int query(int le, int ri) { le += sz; ri += sz; int ret = inf; while (le <= ri) { if (le & 1)ret = min(ret, tree[le++]); if (!(ri & 1))ret = min(ret, tree[ri--]); le /= 2; ri /= 2; } return ret; } }; int p[20005]; int r[55][20005]; int sum[20005]; vector<int> q[20005]; SGT dp[2][55]; void solve(int k) { int now = k & 1; int pre = 1 - now; for (int i = 0; i <= n; i++)dp[now][i].update(0, inf); for (int i = 1; i <= t; i++) { int c = n; int val = inf; int ri = i; int px = 0; for (auto x : q[i]) { int le = ri - (x - px) + 1; if (le <= ri) { int temp = dp[pre][c].query(le - 1, ri - 1); if (temp != inf) val = min(val, temp + c * sum[i]); } c--; ri = le - 1; px = x; } if (1 <= ri) { int temp = dp[pre][c].query(0, ri - 1); if (temp != inf) val = min(val, temp + c * sum[i]); } for (int j = 0; j <= n; j++) dp[now][j].update(i, val - j * sum[i]); if (i == t) printf("%d\n", val); } } int main() { scanf("%d%d%d", &n, &t, &s); for (int i = 1; i <= t; i++) { scanf("%d", &p[i]); sum[i] = sum[i - 1] + p[i]; } for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 1; j <= t; j++) { scanf("%1d", &r[i][j]); if (r[i][j])cnt++; else cnt = 0; q[j].push_back(cnt); } } for (int i = 1; i <= t; i++) sort(q[i].begin(), q[i].end()); for (int i = 1; i <= s; i++) solve(i); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1400 KB | Output is correct |
2 | Correct | 6 ms | 3172 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 156 ms | 5296 KB | Output is correct |
2 | Correct | 133 ms | 5296 KB | Output is correct |
3 | Correct | 150 ms | 5372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 565 ms | 7588 KB | Output is correct |
2 | Correct | 757 ms | 8944 KB | Output is correct |
3 | Correct | 1077 ms | 9832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1400 KB | Output is correct |
2 | Correct | 6 ms | 3172 KB | Output is correct |
3 | Correct | 156 ms | 5296 KB | Output is correct |
4 | Correct | 133 ms | 5296 KB | Output is correct |
5 | Correct | 150 ms | 5372 KB | Output is correct |
6 | Correct | 565 ms | 7588 KB | Output is correct |
7 | Correct | 757 ms | 8944 KB | Output is correct |
8 | Correct | 1077 ms | 9832 KB | Output is correct |
9 | Correct | 1818 ms | 13444 KB | Output is correct |
10 | Execution timed out | 2043 ms | 15488 KB | Time limit exceeded |
11 | Halted | 0 ms | 0 KB | - |