답안 #154390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154390 2019-09-21T16:06:28 Z arnold518 조교 (CEOI16_popeala) C++14
26 / 100
2000 ms 9228 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];

struct SEG
{
    ll A[MAXT+10], SL[MAXT+10][20], SR[MAXT+20][20];

    void init()
    {
        int i, j;
        for(i=0; i<=T; i++) SL[i][0]=SR[i][0]=A[i];
        for(j=1; j<=16; j++) for(i=0; i<=T; i++) SL[i][j]=min(SL[i][j-1], SL[min(T, i+(1<<(j-1)))][j-1]);
        for(j=1; j<=16; j++) for(i=0; i<=T; i++) SR[i][j]=min(SR[i][j-1], SR[max(0, i-(1<<(j-1)))][j-1]);
    }

    ll query(int l, int r)
    {
        int k=31-__builtin_clz(r-l+1);
        //printf("%d %d %d : %lld %lld\n", l, r, k, SL[l][k], SR[r][k]);
        return min(SL[l][k], SR[r][k]);
    }
}seg;

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(j=0; j<=N+1; j++) printf("%d ", V[i][j]); printf("\n");
    }

    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++) seg.A[j]=dp[i-1][j]-k*P[j];
            seg.init();
            for(j=1; j<=T; j++)
            {
                if(V[j][k]==V[j][k+1]) continue;
                dp[i][j]=min(dp[i][j], seg.query(V[j][k], V[j][k+1]-1)+k*P[j]);
            }
            //printf("!%lld ", dp[i][j]);
        }
        //printf("\n");
    }
    for(i=1; i<=S; i++) printf("%lld\n", dp[i][T]);
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:54: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:54: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:39:18: warning: unused variable 'p' [-Wunused-variable]
     int i, j, k, p;
                  ^
popeala.cpp:41: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:42: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:43: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]);
                                             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 6 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 1912 KB Output is correct
2 Correct 129 ms 1784 KB Output is correct
3 Correct 135 ms 1888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 870 ms 3832 KB Output is correct
2 Correct 1402 ms 4852 KB Output is correct
3 Correct 1953 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 6 ms 1144 KB Output is correct
3 Correct 136 ms 1912 KB Output is correct
4 Correct 129 ms 1784 KB Output is correct
5 Correct 135 ms 1888 KB Output is correct
6 Correct 870 ms 3832 KB Output is correct
7 Correct 1402 ms 4852 KB Output is correct
8 Correct 1953 ms 6136 KB Output is correct
9 Execution timed out 2063 ms 9228 KB Time limit exceeded
10 Halted 0 ms 0 KB -