Submission #52863

# Submission time Handle Problem Language Result Execution time Memory
52863 2018-06-27T05:26:58 Z 강태규(#1381) Popeala (CEOI16_popeala) C++11
100 / 100
638 ms 14064 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const llong inf = 1e12;
int n, t, s;
llong pt[20005];
char res[50][20005];
int ep[20005][51];
llong pr[20005];
llong dp[20005];
llong mn[20005][51];

int main() {
    scanf("%d%d%d", &n, &t, &s);
    for (int i = 1; i <= t; ++i) {
        scanf("%lld", pt + i);
        pt[i] += pt[i - 1];
    }
    for (int i = 0; i < n; ++i) {
        scanf("%s", res[i] + 1);
        for (int j = 1; j <= t; ++j) {
            res[i][j] -= '0';
        }
    }
    for (int i = 0; i < n; ++i) {
        ep[t][i] = t + res[i][t];
    }
    for (int i = t; --i; ) {
        for (int j = 0; j < n; ++j) {
            ep[i][j] = res[j][i] ? ep[i + 1][j] : i;
        }
    }
    for (int i = 1; i <= t; ++i) {
        sort(ep[i], ep[i] + n);
    }
    for (int i = 1; i <= t; ++i) dp[i] = inf;
    for (int it = 0; it < s; ++it) {
        for (int i = 0; i <= t; ++i) {
            pr[i] = dp[i];
            dp[i] = inf;
            for (int j = 0; j <= n; ++j) {
                mn[i][j] = inf;
            }
        }
        for (int i = 1; i <= t; ++i) {
            int p = i;
            for (int j = n + 1; j--; ) {
                if (pr[i - 1] != inf)
                    mn[p][j] = min(mn[p][j], pr[i - 1] - j * pt[i - 1]);
                p = ep[i][n - j];
            }
        }
        for (int i = 1; i <= t; ++i) {
            for (int j = 0; j <= n; ++j) {
                mn[i][j] = min(mn[i][j], mn[i - 1][j]);
            }
        }
        for (int i = 1; i <= t; ++i) {
            for (int j = 0; j <= n; ++j) {
                if (mn[i][j] != inf)
                    dp[i] = min(dp[i], mn[i][j] + j * pt[i]);
            }
        }
        printf("%lld\n", dp[t]);
    }
	return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &t, &s);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", pt + i);
         ~~~~~^~~~~~~~~~~~~~~~
popeala.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", res[i] + 1);
         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 920 KB Output is correct
2 Correct 12 ms 1048 KB Output is correct
3 Correct 15 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2236 KB Output is correct
2 Correct 65 ms 2720 KB Output is correct
3 Correct 88 ms 3528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 13 ms 920 KB Output is correct
4 Correct 12 ms 1048 KB Output is correct
5 Correct 15 ms 1108 KB Output is correct
6 Correct 47 ms 2236 KB Output is correct
7 Correct 65 ms 2720 KB Output is correct
8 Correct 88 ms 3528 KB Output is correct
9 Correct 134 ms 5104 KB Output is correct
10 Correct 197 ms 6548 KB Output is correct
11 Correct 592 ms 13996 KB Output is correct
12 Correct 622 ms 14064 KB Output is correct
13 Correct 499 ms 14064 KB Output is correct
14 Correct 454 ms 14064 KB Output is correct
15 Correct 638 ms 14064 KB Output is correct