답안 #589741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589741 2022-07-05T08:24:33 Z andrei_boaca 조교 (CEOI16_popeala) C++14
0 / 100
781 ms 39452 KB
#include <bits/stdc++.h>

using namespace std;
int dp[20005][55];
int cost[4005][4005];
int n,t,s;
int val[20005];
bool have[55][20005];
bool bad[55];
int mycost[55];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>t>>s;
    for(int i=1;i<=t;i++)
        cin>>val[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=t;j++)
        {
            char c;
            cin>>c;
            have[i][j]=c-'0';
        }
    for(int i=1;i<=t;i++)
    {
        for(int j=1;j<=n;j++)
        {
            bad[j]=0;
            mycost[j]=0;
        }
        int cur=0;
        for(int j=i;j<=t;j++)
        {
            for(int k=1;k<=n;k++)
                if(!bad[k])
                {
                    if(have[k][j])
                    {
                        cur+=val[j];
                        mycost[k]+=val[j];
                    }
                    else
                    {
                        bad[k]=1;
                        cur-=mycost[k];
                        mycost[k]=0;
                    }
                }
            cost[i][j]=cur;
        }
    }
    dp[0][0]=0;
    for(int i=1;i<=s;i++)
        dp[0][i]=2e9;
    for(int i=1;i<=t;i++)
    {
        dp[i][0]=2e9;
        for(int j=1;j<=s;j++)
        {
            dp[i][j]=2e9;
            int best=0;
            for(int k=i-1;k>=0;k--)
            {
                if(dp[k][j-1]+cost[k+1][i]<dp[i][j])
                    best=k;
                dp[i][j]=min(dp[i][j],dp[k][j-1]+cost[k+1][i]);
            }
        }
    }
    for(int k=1;k<=s;k++)
        for(int i=2;i<=t;i++)
            assert(dp[i][k]<=dp[i-1][k]);
    for(int i=1;i<=s;i++)
        cout<<dp[t][i]<<'\n';
    return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:62:17: warning: variable 'best' set but not used [-Wunused-but-set-variable]
   62 |             int best=0;
      |                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Runtime error 4 ms 1108 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 6228 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 781 ms 39452 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Runtime error 4 ms 1108 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -