답안 #383158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383158 2021-03-28T23:20:54 Z ScarletS Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
357 ms 135404 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 205;
const ll INF = 1e18;
int md[N*3],l;
ll dp[N][N][N][2];

int d(int x, int y)
{
    return (min(abs(x-y),l-abs(x-y)));
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,ans=1;
    cin>>n>>l;
    int a[n+1],t[n+1];
    a[0]=t[0]=0;
    for (int i=1;i<=n;++i)
    {
        md[i]=i;
        cin>>a[i];
    }
    for (int i=1;i<=n;++i)
        cin>>t[i];
    for (int i=n+1;i<N*3;++i)
        md[i]=md[i-n-1];
    for (int i=0;i<N;++i)
        for (int j=0;j<N;++j)
            for (int k=0;k<N;++k)
                dp[i][j][k][0]=dp[i][j][k][1]=INF;
    dp[1][0][0][0]=0;
    for (int i=1;i<=n+1;++i)
    {
        for (int j=1;j<=n;++j)
            for (int k=0;k<=n;++k)
            {
                dp[i][k][md[k+j]][0]=min({dp[i-1][md[k+1]][md[k+j]][0]+d(a[md[k+1]],a[k]),dp[i-1][md[k+1]][md[k+j]][1]+d(a[md[k+j]],a[k])});
                dp[i][k][md[k+j]][1]=min({dp[i-1][k][md[k+j-1]][1]+d(a[md[k+j]],a[md[k+j-1]]),dp[i-1][k][md[k+j-1]][0]+d(a[md[k+j]],a[k])});
                if (dp[i][k][md[k+j]][0]>t[k])
                    dp[i][k][md[k+j]][0]=INF;
                if (dp[i][k][md[k+j]][1]>t[md[k+j]])
                    dp[i][k][md[k+j]][1]=INF;
            }
        for (int j=1;j<=n;++j)
            for (int k=0;k<=n;++k)
            {
                dp[i][k][md[k+j]][0]=min({dp[i][k][md[k+j]][0],dp[i][md[k+1]][md[k+j]][0]+d(a[md[k+1]],a[k]),dp[i][md[k+1]][md[k+j]][1]+d(a[md[k+j]],a[k])});
                dp[i][k][md[k+j]][1]=min({dp[i][k][md[k+j]][1],dp[i][k][md[k+j-1]][1]+d(a[md[k+j]],a[md[k+j-1]]),dp[i][k][md[k+j-1]][0]+d(a[md[k+j]],a[k])});
            }
    }
    for (int i=1;i<=n+1;++i)
        for (int j=0;j<=n;++j)
            for (int k=0;k<=n;++k)
                if (min({dp[i][j][k][0],dp[i][j][k][1]})<INF)
                    ans=i;
    cout<<ans-1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135296 KB Output is correct
2 Correct 71 ms 135148 KB Output is correct
3 Correct 70 ms 135296 KB Output is correct
4 Correct 73 ms 135276 KB Output is correct
5 Correct 70 ms 135192 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 70 ms 135148 KB Output is correct
8 Correct 72 ms 135148 KB Output is correct
9 Correct 70 ms 135148 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 71 ms 135148 KB Output is correct
12 Correct 72 ms 135376 KB Output is correct
13 Correct 70 ms 135148 KB Output is correct
14 Correct 70 ms 135148 KB Output is correct
15 Correct 71 ms 135148 KB Output is correct
16 Correct 79 ms 135168 KB Output is correct
17 Correct 73 ms 135148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135296 KB Output is correct
2 Correct 71 ms 135148 KB Output is correct
3 Correct 70 ms 135296 KB Output is correct
4 Correct 73 ms 135276 KB Output is correct
5 Correct 70 ms 135192 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 70 ms 135148 KB Output is correct
8 Correct 72 ms 135148 KB Output is correct
9 Correct 70 ms 135148 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 71 ms 135148 KB Output is correct
12 Correct 72 ms 135376 KB Output is correct
13 Correct 70 ms 135148 KB Output is correct
14 Correct 70 ms 135148 KB Output is correct
15 Correct 71 ms 135148 KB Output is correct
16 Correct 79 ms 135168 KB Output is correct
17 Correct 73 ms 135148 KB Output is correct
18 Correct 79 ms 135148 KB Output is correct
19 Correct 71 ms 135276 KB Output is correct
20 Correct 71 ms 135224 KB Output is correct
21 Correct 71 ms 135148 KB Output is correct
22 Correct 74 ms 135148 KB Output is correct
23 Correct 72 ms 135148 KB Output is correct
24 Correct 71 ms 135148 KB Output is correct
25 Correct 73 ms 135148 KB Output is correct
26 Correct 76 ms 135296 KB Output is correct
27 Correct 72 ms 135148 KB Output is correct
28 Correct 71 ms 135148 KB Output is correct
29 Correct 73 ms 135148 KB Output is correct
30 Correct 76 ms 135148 KB Output is correct
31 Correct 71 ms 135276 KB Output is correct
32 Correct 70 ms 135148 KB Output is correct
33 Correct 71 ms 135276 KB Output is correct
34 Correct 72 ms 135148 KB Output is correct
35 Correct 71 ms 135276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135296 KB Output is correct
2 Correct 71 ms 135148 KB Output is correct
3 Correct 70 ms 135296 KB Output is correct
4 Correct 73 ms 135276 KB Output is correct
5 Correct 70 ms 135192 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 70 ms 135148 KB Output is correct
8 Correct 72 ms 135148 KB Output is correct
9 Correct 70 ms 135148 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 71 ms 135148 KB Output is correct
12 Correct 72 ms 135376 KB Output is correct
13 Correct 70 ms 135148 KB Output is correct
14 Correct 70 ms 135148 KB Output is correct
15 Correct 71 ms 135148 KB Output is correct
16 Correct 79 ms 135168 KB Output is correct
17 Correct 73 ms 135148 KB Output is correct
18 Correct 258 ms 135272 KB Output is correct
19 Correct 164 ms 135272 KB Output is correct
20 Correct 112 ms 135276 KB Output is correct
21 Correct 157 ms 135320 KB Output is correct
22 Correct 222 ms 135388 KB Output is correct
23 Correct 100 ms 135148 KB Output is correct
24 Correct 92 ms 135148 KB Output is correct
25 Correct 98 ms 135148 KB Output is correct
26 Correct 81 ms 135148 KB Output is correct
27 Correct 102 ms 135148 KB Output is correct
28 Correct 91 ms 135276 KB Output is correct
29 Correct 101 ms 135148 KB Output is correct
30 Correct 92 ms 135148 KB Output is correct
31 Correct 98 ms 135276 KB Output is correct
32 Correct 86 ms 135276 KB Output is correct
33 Correct 113 ms 135256 KB Output is correct
34 Correct 76 ms 135148 KB Output is correct
35 Correct 99 ms 135148 KB Output is correct
36 Correct 78 ms 135148 KB Output is correct
37 Correct 100 ms 135276 KB Output is correct
38 Correct 85 ms 135148 KB Output is correct
39 Correct 102 ms 135272 KB Output is correct
40 Correct 85 ms 135276 KB Output is correct
41 Correct 325 ms 135276 KB Output is correct
42 Correct 211 ms 135300 KB Output is correct
43 Correct 325 ms 135148 KB Output is correct
44 Correct 215 ms 135148 KB Output is correct
45 Correct 335 ms 135240 KB Output is correct
46 Correct 214 ms 135148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135296 KB Output is correct
2 Correct 71 ms 135148 KB Output is correct
3 Correct 70 ms 135296 KB Output is correct
4 Correct 73 ms 135276 KB Output is correct
5 Correct 70 ms 135192 KB Output is correct
6 Correct 71 ms 135276 KB Output is correct
7 Correct 70 ms 135148 KB Output is correct
8 Correct 72 ms 135148 KB Output is correct
9 Correct 70 ms 135148 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 71 ms 135148 KB Output is correct
12 Correct 72 ms 135376 KB Output is correct
13 Correct 70 ms 135148 KB Output is correct
14 Correct 70 ms 135148 KB Output is correct
15 Correct 71 ms 135148 KB Output is correct
16 Correct 79 ms 135168 KB Output is correct
17 Correct 73 ms 135148 KB Output is correct
18 Correct 79 ms 135148 KB Output is correct
19 Correct 71 ms 135276 KB Output is correct
20 Correct 71 ms 135224 KB Output is correct
21 Correct 71 ms 135148 KB Output is correct
22 Correct 74 ms 135148 KB Output is correct
23 Correct 72 ms 135148 KB Output is correct
24 Correct 71 ms 135148 KB Output is correct
25 Correct 73 ms 135148 KB Output is correct
26 Correct 76 ms 135296 KB Output is correct
27 Correct 72 ms 135148 KB Output is correct
28 Correct 71 ms 135148 KB Output is correct
29 Correct 73 ms 135148 KB Output is correct
30 Correct 76 ms 135148 KB Output is correct
31 Correct 71 ms 135276 KB Output is correct
32 Correct 70 ms 135148 KB Output is correct
33 Correct 71 ms 135276 KB Output is correct
34 Correct 72 ms 135148 KB Output is correct
35 Correct 71 ms 135276 KB Output is correct
36 Correct 258 ms 135272 KB Output is correct
37 Correct 164 ms 135272 KB Output is correct
38 Correct 112 ms 135276 KB Output is correct
39 Correct 157 ms 135320 KB Output is correct
40 Correct 222 ms 135388 KB Output is correct
41 Correct 100 ms 135148 KB Output is correct
42 Correct 92 ms 135148 KB Output is correct
43 Correct 98 ms 135148 KB Output is correct
44 Correct 81 ms 135148 KB Output is correct
45 Correct 102 ms 135148 KB Output is correct
46 Correct 91 ms 135276 KB Output is correct
47 Correct 101 ms 135148 KB Output is correct
48 Correct 92 ms 135148 KB Output is correct
49 Correct 98 ms 135276 KB Output is correct
50 Correct 86 ms 135276 KB Output is correct
51 Correct 113 ms 135256 KB Output is correct
52 Correct 76 ms 135148 KB Output is correct
53 Correct 99 ms 135148 KB Output is correct
54 Correct 78 ms 135148 KB Output is correct
55 Correct 100 ms 135276 KB Output is correct
56 Correct 85 ms 135148 KB Output is correct
57 Correct 102 ms 135272 KB Output is correct
58 Correct 85 ms 135276 KB Output is correct
59 Correct 325 ms 135276 KB Output is correct
60 Correct 211 ms 135300 KB Output is correct
61 Correct 325 ms 135148 KB Output is correct
62 Correct 215 ms 135148 KB Output is correct
63 Correct 335 ms 135240 KB Output is correct
64 Correct 214 ms 135148 KB Output is correct
65 Correct 292 ms 135276 KB Output is correct
66 Correct 268 ms 135300 KB Output is correct
67 Correct 252 ms 135276 KB Output is correct
68 Correct 233 ms 135276 KB Output is correct
69 Correct 294 ms 135404 KB Output is correct
70 Correct 273 ms 135276 KB Output is correct
71 Correct 287 ms 135276 KB Output is correct
72 Correct 278 ms 135276 KB Output is correct
73 Correct 270 ms 135404 KB Output is correct
74 Correct 239 ms 135276 KB Output is correct
75 Correct 262 ms 135276 KB Output is correct
76 Correct 317 ms 135276 KB Output is correct
77 Correct 309 ms 135404 KB Output is correct
78 Correct 244 ms 135276 KB Output is correct
79 Correct 242 ms 135276 KB Output is correct
80 Correct 310 ms 135324 KB Output is correct
81 Correct 247 ms 135276 KB Output is correct
82 Correct 257 ms 135276 KB Output is correct
83 Correct 320 ms 135276 KB Output is correct
84 Correct 269 ms 135392 KB Output is correct
85 Correct 310 ms 135276 KB Output is correct
86 Correct 326 ms 135276 KB Output is correct
87 Correct 269 ms 135404 KB Output is correct
88 Correct 357 ms 135276 KB Output is correct
89 Correct 337 ms 135276 KB Output is correct
90 Correct 266 ms 135280 KB Output is correct
91 Correct 336 ms 135276 KB Output is correct
92 Correct 347 ms 135276 KB Output is correct
93 Correct 321 ms 135276 KB Output is correct