# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
52908 | 2018-06-27T07:15:54 Z | 0^0(#1376) | 조교 (CEOI16_popeala) | C++11 | 2000 ms | 75380 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, t, s; const ll inf = 0x3f3f3f3f3f3f3f3f; struct SGT { ll tree[20005 << 2]; int sz; SGT() { memset(tree, 0x3f, sizeof(tree)); sz = 1; while (sz < 20005)sz *= 2; } void init() { memset(tree, 0x3f, sizeof(tree)); } void update(int idx, ll val) { idx += sz; tree[idx] = val; idx /= 2; while (idx) { tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]); idx /= 2; } } ll query(int le, int ri) { le += sz; ri += sz; ll 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]; ll 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].init(); for (int i = 1; i <= t; i++) { int c = n; ll val = inf; int ri = i; int px = 0; for (auto x: q[i]) { int le = ri - (x - px) + 1; ll temp = dp[pre][c].query(le - 1, ri - 1) + c * sum[i]; c--; ri = le - 1; val = min(val, temp); px = x; } ll temp = dp[pre][c].query(0, ri - 1) + c*sum[i]; val = min(val, temp); for (int j = 0; j <= n; j++) dp[now][j].update(i, val - j * sum[i]); if (i == t) printf("%lld\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 = 0; i <= n; i++) dp[0][i].update(0, 0); for (int i = 1; i <= s; i++) solve(i); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 69624 KB | Output is correct |
2 | Correct | 138 ms | 69860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 545 ms | 70320 KB | Output is correct |
2 | Correct | 520 ms | 70320 KB | Output is correct |
3 | Correct | 551 ms | 70356 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 900 ms | 71144 KB | Output is correct |
2 | Correct | 1205 ms | 71724 KB | Output is correct |
3 | Correct | 1388 ms | 72424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 69624 KB | Output is correct |
2 | Correct | 138 ms | 69860 KB | Output is correct |
3 | Correct | 545 ms | 70320 KB | Output is correct |
4 | Correct | 520 ms | 70320 KB | Output is correct |
5 | Correct | 551 ms | 70356 KB | Output is correct |
6 | Correct | 900 ms | 71144 KB | Output is correct |
7 | Correct | 1205 ms | 71724 KB | Output is correct |
8 | Correct | 1388 ms | 72424 KB | Output is correct |
9 | Correct | 1871 ms | 74080 KB | Output is correct |
10 | Execution timed out | 2073 ms | 75380 KB | Time limit exceeded |
11 | Halted | 0 ms | 0 KB | - |