답안 #58993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58993 2018-07-20T01:47:43 Z red1108 요리 강좌 (KOI17_cook) C++17
100 / 100
995 ms 271416 KB
#include <vector>
#include <stdio.h>
#include <deque>
using namespace std;
const int inf=1500000000;
vector<vector<int>> input,sum;
vector<int> dp[3010];
struct DATA{
    int value;
    int before;
}mindp[6010][3];
deque<pair<int,int>> dq[3010];
int n, m, row, limit, change, cant[3010];
int getmin(int i, int j)
{
    if(i<row) return (-1)*change;
    if(mindp[i][0].before!=cant[j]&&mindp[i][0].before!=j) return mindp[i][0].value;
    else if(mindp[i][1].before!=cant[j]&&mindp[i][1].before!=j) return mindp[i][1].value;
    else if(mindp[i][2].before!=cant[j]&&mindp[i][2].before!=j) return mindp[i][2].value;
}
void gang(int i, int j,int bac)
{
    if(j<1) return;
    if(mindp[i][0].value>=j)
    {
        mindp[i][2]=mindp[i][1];
        mindp[i][1]=mindp[i][0];
        mindp[i][0].value=j;
        mindp[i][0].before=bac;
    }
    else if(mindp[i][1].value>=j)
    {
        mindp[i][2]=mindp[i][1];
        mindp[i][1].value=j;
        mindp[i][1].before=bac;
    }
    else if(mindp[i][2].value>=j)
    {
        mindp[i][2].value=j;
        mindp[i][2].before=bac;
    }
}
int main()
{
    int i, j, ina;
    scanf("%d %d %d %d %d", &n, &m, &row, &limit, &change);
    input.push_back(vector<int>{0});
    sum.push_back(vector<int>{0});
    for(i=1;i<=n;i++)
    {
        input.push_back(vector<int>{0});
        sum.push_back(vector<int>{0});
        dp[i].push_back(0);
        for(j=1;j<=m;j++)
        {
            scanf("%d",&ina);
            input[i].push_back(ina);
            sum[i].push_back(sum[i][j-1]+ina);
            dp[i].push_back(0);
        }
        for(j=1;j<=m;j++) {sum[i].push_back(sum[i][sum[i].size()-1]);input[i].push_back(0);dp[i].push_back(0);}
    }
    for(i=1;i<=n;i++) scanf("%d", &cant[i]);
    for(i=row;i<=m+row-1;i++)
    {
        for(j=0;j<3;j++) mindp[i][j].value=inf;
        for(j=1;j<=n;j++)
        {
            while(!dq[j].empty()&&dq[j].front().second<i-limit+1) dq[j].pop_front();
            pair<int,int> newput={getmin(i-row,j)+change,i-row+1};
            if(i-row>=row||i<=limit){
                if(i-row<row&&i<=limit) newput.second=1;
                while(!dq[j].empty()&&(dq[j].back().first+sum[j][i]-sum[j][dq[j].back().second-1]>=newput.first+sum[j][i]-sum[j][i-row]||dq[j].back().second<i-limit+1)) dq[j].pop_back();
                dq[j].push_back(newput);
            }
            if(dq[j].front().first>=inf||dq[j].empty()) dp[j][i]=inf;
            else dp[j][i]=dq[j].front().first+sum[j][i]-sum[j][dq[j].front().second-1];
            gang(i,dp[j][i],j);
        }
    }
    int ans=inf;
    for(i=1;i<=n;i++)
    {
        for(j=m;j<=m+row-1;j++)
        {
            ans=dp[i][j]<ans&&dp[i][j]>0?dp[i][j]:ans;
        }
    }
    printf("%d",ans);
}

Compilation message

cook.cpp: In function 'int getmin(int, int)':
cook.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
cook.cpp: In function 'int main()':
cook.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d %d", &n, &m, &row, &limit, &change);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cook.cpp:56:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&ina);
             ~~~~~^~~~~~~~~~~
cook.cpp:63:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++) scanf("%d", &cant[i]);
                       ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 5 ms 2552 KB Output is correct
3 Correct 5 ms 2588 KB Output is correct
4 Correct 4 ms 2588 KB Output is correct
5 Correct 5 ms 2720 KB Output is correct
6 Correct 5 ms 2780 KB Output is correct
7 Correct 6 ms 2780 KB Output is correct
8 Correct 6 ms 2780 KB Output is correct
9 Correct 6 ms 2952 KB Output is correct
10 Correct 5 ms 2952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 5 ms 2552 KB Output is correct
3 Correct 5 ms 2588 KB Output is correct
4 Correct 4 ms 2588 KB Output is correct
5 Correct 5 ms 2720 KB Output is correct
6 Correct 5 ms 2780 KB Output is correct
7 Correct 6 ms 2780 KB Output is correct
8 Correct 6 ms 2780 KB Output is correct
9 Correct 6 ms 2952 KB Output is correct
10 Correct 28 ms 6744 KB Output is correct
11 Correct 19 ms 6744 KB Output is correct
12 Correct 29 ms 6788 KB Output is correct
13 Correct 22 ms 6788 KB Output is correct
14 Correct 42 ms 6788 KB Output is correct
15 Correct 25 ms 6788 KB Output is correct
16 Correct 31 ms 6788 KB Output is correct
17 Correct 18 ms 6788 KB Output is correct
18 Correct 27 ms 6788 KB Output is correct
19 Correct 17 ms 6788 KB Output is correct
20 Correct 5 ms 2952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 5 ms 2552 KB Output is correct
3 Correct 5 ms 2588 KB Output is correct
4 Correct 4 ms 2588 KB Output is correct
5 Correct 5 ms 2720 KB Output is correct
6 Correct 5 ms 2780 KB Output is correct
7 Correct 6 ms 2780 KB Output is correct
8 Correct 6 ms 2780 KB Output is correct
9 Correct 6 ms 2952 KB Output is correct
10 Correct 28 ms 6744 KB Output is correct
11 Correct 19 ms 6744 KB Output is correct
12 Correct 29 ms 6788 KB Output is correct
13 Correct 22 ms 6788 KB Output is correct
14 Correct 42 ms 6788 KB Output is correct
15 Correct 25 ms 6788 KB Output is correct
16 Correct 31 ms 6788 KB Output is correct
17 Correct 18 ms 6788 KB Output is correct
18 Correct 27 ms 6788 KB Output is correct
19 Correct 17 ms 6788 KB Output is correct
20 Correct 258 ms 39416 KB Output is correct
21 Correct 274 ms 44396 KB Output is correct
22 Correct 274 ms 49288 KB Output is correct
23 Correct 243 ms 54172 KB Output is correct
24 Correct 269 ms 59068 KB Output is correct
25 Correct 379 ms 64192 KB Output is correct
26 Correct 277 ms 68920 KB Output is correct
27 Correct 256 ms 73796 KB Output is correct
28 Correct 278 ms 78696 KB Output is correct
29 Correct 250 ms 83620 KB Output is correct
30 Correct 5 ms 2952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 5 ms 2552 KB Output is correct
3 Correct 5 ms 2588 KB Output is correct
4 Correct 4 ms 2588 KB Output is correct
5 Correct 5 ms 2720 KB Output is correct
6 Correct 5 ms 2780 KB Output is correct
7 Correct 6 ms 2780 KB Output is correct
8 Correct 6 ms 2780 KB Output is correct
9 Correct 6 ms 2952 KB Output is correct
10 Correct 28 ms 6744 KB Output is correct
11 Correct 19 ms 6744 KB Output is correct
12 Correct 29 ms 6788 KB Output is correct
13 Correct 22 ms 6788 KB Output is correct
14 Correct 42 ms 6788 KB Output is correct
15 Correct 25 ms 6788 KB Output is correct
16 Correct 31 ms 6788 KB Output is correct
17 Correct 18 ms 6788 KB Output is correct
18 Correct 27 ms 6788 KB Output is correct
19 Correct 17 ms 6788 KB Output is correct
20 Correct 230 ms 83620 KB Output is correct
21 Correct 229 ms 83620 KB Output is correct
22 Correct 198 ms 83620 KB Output is correct
23 Correct 207 ms 83620 KB Output is correct
24 Correct 246 ms 83620 KB Output is correct
25 Correct 224 ms 83620 KB Output is correct
26 Correct 256 ms 83620 KB Output is correct
27 Correct 247 ms 83620 KB Output is correct
28 Correct 243 ms 87704 KB Output is correct
29 Correct 247 ms 92660 KB Output is correct
30 Correct 5 ms 2952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 5 ms 2552 KB Output is correct
3 Correct 5 ms 2588 KB Output is correct
4 Correct 4 ms 2588 KB Output is correct
5 Correct 5 ms 2720 KB Output is correct
6 Correct 5 ms 2780 KB Output is correct
7 Correct 6 ms 2780 KB Output is correct
8 Correct 6 ms 2780 KB Output is correct
9 Correct 6 ms 2952 KB Output is correct
10 Correct 28 ms 6744 KB Output is correct
11 Correct 19 ms 6744 KB Output is correct
12 Correct 29 ms 6788 KB Output is correct
13 Correct 22 ms 6788 KB Output is correct
14 Correct 42 ms 6788 KB Output is correct
15 Correct 25 ms 6788 KB Output is correct
16 Correct 31 ms 6788 KB Output is correct
17 Correct 18 ms 6788 KB Output is correct
18 Correct 27 ms 6788 KB Output is correct
19 Correct 17 ms 6788 KB Output is correct
20 Correct 258 ms 39416 KB Output is correct
21 Correct 274 ms 44396 KB Output is correct
22 Correct 274 ms 49288 KB Output is correct
23 Correct 243 ms 54172 KB Output is correct
24 Correct 269 ms 59068 KB Output is correct
25 Correct 379 ms 64192 KB Output is correct
26 Correct 277 ms 68920 KB Output is correct
27 Correct 256 ms 73796 KB Output is correct
28 Correct 278 ms 78696 KB Output is correct
29 Correct 250 ms 83620 KB Output is correct
30 Correct 230 ms 83620 KB Output is correct
31 Correct 229 ms 83620 KB Output is correct
32 Correct 198 ms 83620 KB Output is correct
33 Correct 207 ms 83620 KB Output is correct
34 Correct 246 ms 83620 KB Output is correct
35 Correct 224 ms 83620 KB Output is correct
36 Correct 256 ms 83620 KB Output is correct
37 Correct 247 ms 83620 KB Output is correct
38 Correct 243 ms 87704 KB Output is correct
39 Correct 247 ms 92660 KB Output is correct
40 Correct 317 ms 107440 KB Output is correct
41 Correct 898 ms 172640 KB Output is correct
42 Correct 995 ms 187216 KB Output is correct
43 Correct 881 ms 191704 KB Output is correct
44 Correct 398 ms 191704 KB Output is correct
45 Correct 575 ms 191704 KB Output is correct
46 Correct 588 ms 205564 KB Output is correct
47 Correct 658 ms 235344 KB Output is correct
48 Correct 805 ms 257280 KB Output is correct
49 Correct 825 ms 271416 KB Output is correct
50 Correct 5 ms 2952 KB Output is correct