Submission #154496

# Submission time Handle Problem Language Result Execution time Memory
154496 2019-09-22T08:26:53 Z arnold518 Popeala (CEOI16_popeala) C++14
100 / 100
1215 ms 19400 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 50;
const int MAXT = 20000;
const ll INF = 1e15;

int N, T, S, P[MAXT+10], R[MAXN+10][MAXT+10];
vector<int> V[MAXT+10];
int cnt[MAXN+10];
ll dp[MAXN+10][MAXT+10], A[MAXT+10];

int main()
{
    int i, j, k, p;

    scanf("%d%d%d", &N, &T, &S);
    for(i=1; i<=T; i++) scanf("%d", &P[i]), P[i]+=P[i-1];
    for(i=1; i<=N; i++) for(j=1; j<=T; j++) scanf("%1d", &R[i][j]);

    for(i=1; i<=T; i++)
    {
        for(j=1; j<=N; j++) if(R[j][i]==0) cnt[j]=i;
        for(j=1; j<=N; j++) V[i].push_back(cnt[j]);
        V[i].push_back(i); V[i].push_back(0);
        sort(V[i].begin(), V[i].end());
    }

    for(i=0; i<=S; i++) for(j=0; j<=T; j++) dp[i][j]=INF; dp[0][0]=0;
    for(i=1; i<=S; i++)
    {
        for(k=0; k<=N; k++)
        {
            for(j=0; j<=T; j++) A[j]=dp[i-1][j]-k*P[j];

            deque<int> DQ;
            for(j=1; j<=T; j++)
            {
                if(V[j][k]==V[j][k+1]) continue;

                while(!DQ.empty() && DQ.front()<V[j][k]) DQ.pop_front();
                if(DQ.empty()) p=V[j][k];
                else p=DQ.back()+1;
                for(; p<V[j][k+1]; p++)
                {
                    while(!DQ.empty() && A[DQ.back()]>=A[p]) DQ.pop_back();
                    DQ.push_back(p);
                }
                dp[i][j]=min(dp[i][j], A[DQ.front()]+k*P[j]);
            }
        }
    }
    for(i=1; i<=S; i++) printf("%lld\n", dp[i][T]);
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:33:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=0; i<=S; i++) for(j=0; j<=T; j++) dp[i][j]=INF; dp[0][0]=0;
     ^~~
popeala.cpp:33:59: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(i=0; i<=S; i++) for(j=0; j<=T; j++) dp[i][j]=INF; dp[0][0]=0;
                                                           ^~
popeala.cpp:21: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:22:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=T; i++) scanf("%d", &P[i]), P[i]+=P[i-1];
                         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
popeala.cpp:23:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) for(j=1; j<=T; j++) scanf("%1d", &R[i][j]);
                                             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1656 KB Output is correct
2 Correct 28 ms 1656 KB Output is correct
3 Correct 29 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3288 KB Output is correct
2 Correct 185 ms 4052 KB Output is correct
3 Correct 243 ms 4980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 30 ms 1656 KB Output is correct
4 Correct 28 ms 1656 KB Output is correct
5 Correct 29 ms 1656 KB Output is correct
6 Correct 131 ms 3288 KB Output is correct
7 Correct 185 ms 4052 KB Output is correct
8 Correct 243 ms 4980 KB Output is correct
9 Correct 342 ms 7308 KB Output is correct
10 Correct 524 ms 9080 KB Output is correct
11 Correct 1056 ms 19192 KB Output is correct
12 Correct 1089 ms 19392 KB Output is correct
13 Correct 1162 ms 19400 KB Output is correct
14 Correct 1215 ms 19400 KB Output is correct
15 Correct 1154 ms 19396 KB Output is correct