답안 #217971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217971 2020-03-31T11:23:30 Z KoalaMuch Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
223 ms 270332 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 205;
int dp[N][N*2][N*2][2];
//dp[i][j][k][0] = collect i stamp from j th -> k th : 0 = at j 1 = at k
int a[N*2];
int t[N*2];
int L;
int cal(int i,int j)
{
    if(i>j) swap(i,j);
    return min(j-i,i+L-j);
}
int main()
{
    memset(dp,127,sizeof dp);
    int n,ans = 0;
    scanf("%d %d",&n,&L);
    for(int i=1;i<=n;i++)   scanf("%d",&a[i]),a[i+n+1] = a[i];
    for(int i=1;i<=n;i++)   scanf("%d",&t[i]),t[i+n+1] = t[i];
    dp[0][n+1][n+1][0] = dp[0][n+1][n+1][1] = 0;
    for(int i=0;i<=n;i++)
    {
        for(int l=0;l<=n;l++)
        {
            for(int j=n+1-l,k=n+1;j<=n+1;j++,k++)
            {
                if(dp[i][j][k][0]<=1e9)
                {
                    ans = i;
                    if(l!=n)
                    {
                        if(j-1!=0)
                        {
                            int v = dp[i][j][k][0]+cal(a[j-1],a[j]);
                            dp[i][j-1][k][0] = min(dp[i][j-1][k][0],v);
                            if(v<=t[j-1])   dp[i+1][j-1][k][0] = min(dp[i+1][j-1][k][0],v);
                        }
                        if(k+1<=2*n+1)
                        {
                            int v = dp[i][j][k][0]+cal(a[j],a[k+1]);
                            dp[i][j][k+1][1] = min(dp[i][j][k+1][1],v);
                            if(v<=t[k+1])   dp[i+1][j][k+1][1] = min(dp[i+1][j][k+1][1],v);
                        }
                    }
                }
                if(dp[i][j][k][1]<=1e9)
                {
//                    if(i==3&&j==5&&k==9)    printf("---");
                    ans = i;
                    if(l!=n)
                    {
                        if(j-1!=0)
                        {
                            int v = dp[i][j][k][1]+cal(a[j-1],a[k]);
                            dp[i][j-1][k][0] = min(dp[i][j-1][k][0],v);
                            if(v<=t[j-1])   dp[i+1][j-1][k][0] = min(dp[i+1][j-1][k][0],v);
                        }
                        if(k+1<=2*n+1)
                        {
                            int v = dp[i][j][k][1]+cal(a[k],a[k+1]);
                            dp[i][j][k+1][1] = min(dp[i][j][k+1][1],v);
                            if(v<=t[k+1])   dp[i+1][j][k+1][1] = min(dp[i+1][j][k+1][1],v);
                        }
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}
/*
6 25
3 4 7 17 21 23
11 7 17 10 8 10
(4)

5 20
4 5 8 13 17
18 23 15 7 10
(5)

10 87
9 23 33 38 42 44 45 62 67 78
15 91 7 27 31 53 12 91 89 46
(5)

4 19
3 7 12 14
2 0 5 4
(0)
*/

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&L);
     ~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:19:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)   scanf("%d",&a[i]),a[i+n+1] = a[i];
                             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:20:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)   scanf("%d",&t[i]),t[i+n+1] = t[i];
                             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 270072 KB Output is correct
2 Correct 144 ms 270072 KB Output is correct
3 Correct 145 ms 270072 KB Output is correct
4 Correct 154 ms 270072 KB Output is correct
5 Correct 154 ms 270072 KB Output is correct
6 Correct 146 ms 270072 KB Output is correct
7 Correct 145 ms 270072 KB Output is correct
8 Correct 146 ms 270200 KB Output is correct
9 Correct 147 ms 270072 KB Output is correct
10 Correct 145 ms 270072 KB Output is correct
11 Correct 150 ms 270072 KB Output is correct
12 Correct 154 ms 270176 KB Output is correct
13 Correct 143 ms 270072 KB Output is correct
14 Correct 146 ms 270072 KB Output is correct
15 Correct 148 ms 270072 KB Output is correct
16 Correct 150 ms 270072 KB Output is correct
17 Correct 147 ms 270072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 270072 KB Output is correct
2 Correct 144 ms 270072 KB Output is correct
3 Correct 145 ms 270072 KB Output is correct
4 Correct 154 ms 270072 KB Output is correct
5 Correct 154 ms 270072 KB Output is correct
6 Correct 146 ms 270072 KB Output is correct
7 Correct 145 ms 270072 KB Output is correct
8 Correct 146 ms 270200 KB Output is correct
9 Correct 147 ms 270072 KB Output is correct
10 Correct 145 ms 270072 KB Output is correct
11 Correct 150 ms 270072 KB Output is correct
12 Correct 154 ms 270176 KB Output is correct
13 Correct 143 ms 270072 KB Output is correct
14 Correct 146 ms 270072 KB Output is correct
15 Correct 148 ms 270072 KB Output is correct
16 Correct 150 ms 270072 KB Output is correct
17 Correct 147 ms 270072 KB Output is correct
18 Correct 157 ms 270072 KB Output is correct
19 Correct 150 ms 270308 KB Output is correct
20 Correct 145 ms 270072 KB Output is correct
21 Correct 146 ms 270072 KB Output is correct
22 Correct 155 ms 270072 KB Output is correct
23 Correct 156 ms 270024 KB Output is correct
24 Correct 152 ms 270072 KB Output is correct
25 Correct 144 ms 270072 KB Output is correct
26 Correct 156 ms 270072 KB Output is correct
27 Correct 145 ms 270072 KB Output is correct
28 Correct 142 ms 270072 KB Output is correct
29 Correct 144 ms 270072 KB Output is correct
30 Correct 157 ms 270200 KB Output is correct
31 Correct 143 ms 270072 KB Output is correct
32 Correct 143 ms 270072 KB Output is correct
33 Correct 143 ms 270072 KB Output is correct
34 Correct 148 ms 270200 KB Output is correct
35 Correct 141 ms 270072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 270072 KB Output is correct
2 Correct 144 ms 270072 KB Output is correct
3 Correct 145 ms 270072 KB Output is correct
4 Correct 154 ms 270072 KB Output is correct
5 Correct 154 ms 270072 KB Output is correct
6 Correct 146 ms 270072 KB Output is correct
7 Correct 145 ms 270072 KB Output is correct
8 Correct 146 ms 270200 KB Output is correct
9 Correct 147 ms 270072 KB Output is correct
10 Correct 145 ms 270072 KB Output is correct
11 Correct 150 ms 270072 KB Output is correct
12 Correct 154 ms 270176 KB Output is correct
13 Correct 143 ms 270072 KB Output is correct
14 Correct 146 ms 270072 KB Output is correct
15 Correct 148 ms 270072 KB Output is correct
16 Correct 150 ms 270072 KB Output is correct
17 Correct 147 ms 270072 KB Output is correct
18 Correct 180 ms 270072 KB Output is correct
19 Correct 163 ms 270236 KB Output is correct
20 Correct 149 ms 270072 KB Output is correct
21 Correct 156 ms 270072 KB Output is correct
22 Correct 167 ms 270040 KB Output is correct
23 Correct 156 ms 270204 KB Output is correct
24 Correct 145 ms 270072 KB Output is correct
25 Correct 153 ms 270072 KB Output is correct
26 Correct 144 ms 270076 KB Output is correct
27 Correct 153 ms 270120 KB Output is correct
28 Correct 143 ms 270072 KB Output is correct
29 Correct 150 ms 270072 KB Output is correct
30 Correct 143 ms 270072 KB Output is correct
31 Correct 152 ms 270072 KB Output is correct
32 Correct 144 ms 270072 KB Output is correct
33 Correct 150 ms 270072 KB Output is correct
34 Correct 145 ms 270072 KB Output is correct
35 Correct 146 ms 270072 KB Output is correct
36 Correct 150 ms 270072 KB Output is correct
37 Correct 148 ms 270072 KB Output is correct
38 Correct 159 ms 270028 KB Output is correct
39 Correct 151 ms 270072 KB Output is correct
40 Correct 142 ms 270072 KB Output is correct
41 Correct 200 ms 270200 KB Output is correct
42 Correct 156 ms 270048 KB Output is correct
43 Correct 197 ms 270072 KB Output is correct
44 Correct 156 ms 270072 KB Output is correct
45 Correct 194 ms 270072 KB Output is correct
46 Correct 165 ms 270072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 270072 KB Output is correct
2 Correct 144 ms 270072 KB Output is correct
3 Correct 145 ms 270072 KB Output is correct
4 Correct 154 ms 270072 KB Output is correct
5 Correct 154 ms 270072 KB Output is correct
6 Correct 146 ms 270072 KB Output is correct
7 Correct 145 ms 270072 KB Output is correct
8 Correct 146 ms 270200 KB Output is correct
9 Correct 147 ms 270072 KB Output is correct
10 Correct 145 ms 270072 KB Output is correct
11 Correct 150 ms 270072 KB Output is correct
12 Correct 154 ms 270176 KB Output is correct
13 Correct 143 ms 270072 KB Output is correct
14 Correct 146 ms 270072 KB Output is correct
15 Correct 148 ms 270072 KB Output is correct
16 Correct 150 ms 270072 KB Output is correct
17 Correct 147 ms 270072 KB Output is correct
18 Correct 157 ms 270072 KB Output is correct
19 Correct 150 ms 270308 KB Output is correct
20 Correct 145 ms 270072 KB Output is correct
21 Correct 146 ms 270072 KB Output is correct
22 Correct 155 ms 270072 KB Output is correct
23 Correct 156 ms 270024 KB Output is correct
24 Correct 152 ms 270072 KB Output is correct
25 Correct 144 ms 270072 KB Output is correct
26 Correct 156 ms 270072 KB Output is correct
27 Correct 145 ms 270072 KB Output is correct
28 Correct 142 ms 270072 KB Output is correct
29 Correct 144 ms 270072 KB Output is correct
30 Correct 157 ms 270200 KB Output is correct
31 Correct 143 ms 270072 KB Output is correct
32 Correct 143 ms 270072 KB Output is correct
33 Correct 143 ms 270072 KB Output is correct
34 Correct 148 ms 270200 KB Output is correct
35 Correct 141 ms 270072 KB Output is correct
36 Correct 180 ms 270072 KB Output is correct
37 Correct 163 ms 270236 KB Output is correct
38 Correct 149 ms 270072 KB Output is correct
39 Correct 156 ms 270072 KB Output is correct
40 Correct 167 ms 270040 KB Output is correct
41 Correct 156 ms 270204 KB Output is correct
42 Correct 145 ms 270072 KB Output is correct
43 Correct 153 ms 270072 KB Output is correct
44 Correct 144 ms 270076 KB Output is correct
45 Correct 153 ms 270120 KB Output is correct
46 Correct 143 ms 270072 KB Output is correct
47 Correct 150 ms 270072 KB Output is correct
48 Correct 143 ms 270072 KB Output is correct
49 Correct 152 ms 270072 KB Output is correct
50 Correct 144 ms 270072 KB Output is correct
51 Correct 150 ms 270072 KB Output is correct
52 Correct 145 ms 270072 KB Output is correct
53 Correct 146 ms 270072 KB Output is correct
54 Correct 150 ms 270072 KB Output is correct
55 Correct 148 ms 270072 KB Output is correct
56 Correct 159 ms 270028 KB Output is correct
57 Correct 151 ms 270072 KB Output is correct
58 Correct 142 ms 270072 KB Output is correct
59 Correct 200 ms 270200 KB Output is correct
60 Correct 156 ms 270048 KB Output is correct
61 Correct 197 ms 270072 KB Output is correct
62 Correct 156 ms 270072 KB Output is correct
63 Correct 194 ms 270072 KB Output is correct
64 Correct 165 ms 270072 KB Output is correct
65 Correct 177 ms 270048 KB Output is correct
66 Correct 180 ms 270048 KB Output is correct
67 Correct 168 ms 270072 KB Output is correct
68 Correct 165 ms 270072 KB Output is correct
69 Correct 189 ms 270072 KB Output is correct
70 Correct 198 ms 270020 KB Output is correct
71 Correct 168 ms 270072 KB Output is correct
72 Correct 201 ms 270072 KB Output is correct
73 Correct 167 ms 270072 KB Output is correct
74 Correct 191 ms 270072 KB Output is correct
75 Correct 167 ms 270072 KB Output is correct
76 Correct 223 ms 270072 KB Output is correct
77 Correct 174 ms 270072 KB Output is correct
78 Correct 190 ms 270072 KB Output is correct
79 Correct 175 ms 270332 KB Output is correct
80 Correct 211 ms 270072 KB Output is correct
81 Correct 166 ms 270072 KB Output is correct
82 Correct 168 ms 270072 KB Output is correct
83 Correct 175 ms 270072 KB Output is correct
84 Correct 173 ms 270072 KB Output is correct
85 Correct 171 ms 270072 KB Output is correct
86 Correct 188 ms 270200 KB Output is correct
87 Correct 172 ms 270072 KB Output is correct
88 Correct 208 ms 270072 KB Output is correct
89 Correct 180 ms 270072 KB Output is correct
90 Correct 159 ms 270072 KB Output is correct
91 Correct 209 ms 270072 KB Output is correct
92 Correct 184 ms 270096 KB Output is correct
93 Correct 171 ms 270072 KB Output is correct