답안 #212548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212548 2020-03-23T12:58:12 Z DystoriaX Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
83 ms 68224 KB
#include <bits/stdc++.h>

using namespace std;

int n, l;
int x[210], t[210];
int dp[210][210][210][2];
const int MAX = 1e9 + 1;

int getDist(int i, int j){
    int ret = x[i] - x[j]; ret %= l;

    if(ret < 0) ret += l;

    return min(ret, l - ret);
}

int main(){
    scanf("%d%d", &n, &l);

    for(int i = 1; i <= n; i++) scanf("%d", &x[i]);
    for(int i = 1; i <= n; i++) scanf("%d", &t[i]);
    
    for(int i = 0; i <= n + 1; i++)
        for(int j = 0; j <= n + 1; j++)
            for(int k = 0; k <= n + 1; k++)
                dp[i][j][k][0] = dp[i][j][k][1] = MAX;

    dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;

    for(int len = n + 1; len >= 1; len--){
        for(int i = 0; i + len <= n + 1; i++){
            int j = i + len;

            for(int k = 0; k <= n; k++){
                // if(k == 5 && dp[i][j][k][0] != MAX) printf("dp[%d][%d][%d][0] = %d\n", i, j, k, dp[i][j][k][0]);
                // if(k == 5 && dp[i][j][k][1] != MAX) printf("dp[%d][%d][%d][1] = %d\n", i, j, k, dp[i][j][k][1]);
            
                int dist;

                //Position on right [clockwise]
                if(dp[i][j][k][0] != MAX){
                    //From i to i + 1
                    dist = getDist(i, i + 1);
                    dist += dp[i][j][k][0];

                    if(dist <= t[i + 1])
                        dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], dist);
                    else 
                        dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], dist);

                    //From i to j - 1
                    dist = getDist(i, j - 1);
                    dist += dp[i][j][k][0];

                    if(dist <= t[j - 1])
                        dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], dist);
                    else
                        dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], dist);
                }

                //Position on left [counter clockwise]
                if(dp[i][j][k][1] != MAX){
                    //From j to j - 1
                    dist = getDist(j, j - 1);
                    dist += dp[i][j][k][1];

                    if(dist <= t[j - 1])
                        dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], dist);
                    else
                        dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], dist);

                    //From j to i + 1
                    dist = getDist(j, i + 1);                    
                    dist += dp[i][j][k][1];

                    if(dist <= t[i + 1])
                        dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], dist);
                    else 
                        dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], dist);
                }
            }
        }
    }

    int ans = 0;

    for(int i = 0; i <= n; i++)
        for(int cnt = 0; cnt <= n; cnt++)
            if(dp[i][i + 1][cnt][0] != MAX || dp[i][i + 1][cnt][1] != MAX)
                ans = max(ans, cnt);

    printf("%d\n", ans);

    return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:19: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:21:38: 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", &x[i]);
                                 ~~~~~^~~~~~~~~~~~~
ho_t3.cpp:22:38: 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]);
                                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 5 ms 640 KB Output is correct
23 Correct 5 ms 896 KB Output is correct
24 Correct 5 ms 768 KB Output is correct
25 Correct 5 ms 768 KB Output is correct
26 Correct 5 ms 768 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 896 KB Output is correct
30 Correct 5 ms 896 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 5 ms 768 KB Output is correct
33 Correct 5 ms 896 KB Output is correct
34 Correct 5 ms 896 KB Output is correct
35 Correct 5 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 56 ms 54912 KB Output is correct
19 Correct 33 ms 33536 KB Output is correct
20 Correct 17 ms 18176 KB Output is correct
21 Correct 31 ms 31616 KB Output is correct
22 Correct 42 ms 40960 KB Output is correct
23 Correct 17 ms 15488 KB Output is correct
24 Correct 14 ms 12280 KB Output is correct
25 Correct 16 ms 15232 KB Output is correct
26 Correct 8 ms 6016 KB Output is correct
27 Correct 18 ms 15744 KB Output is correct
28 Correct 11 ms 11392 KB Output is correct
29 Correct 16 ms 16128 KB Output is correct
30 Correct 13 ms 12800 KB Output is correct
31 Correct 16 ms 15104 KB Output is correct
32 Correct 9 ms 8192 KB Output is correct
33 Correct 16 ms 15104 KB Output is correct
34 Correct 8 ms 5632 KB Output is correct
35 Correct 13 ms 14848 KB Output is correct
36 Correct 9 ms 7296 KB Output is correct
37 Correct 14 ms 15872 KB Output is correct
38 Correct 10 ms 8832 KB Output is correct
39 Correct 16 ms 16384 KB Output is correct
40 Correct 13 ms 9856 KB Output is correct
41 Correct 74 ms 67576 KB Output is correct
42 Correct 32 ms 45696 KB Output is correct
43 Correct 83 ms 67676 KB Output is correct
44 Correct 31 ms 45184 KB Output is correct
45 Correct 75 ms 67576 KB Output is correct
46 Correct 33 ms 45824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 5 ms 640 KB Output is correct
23 Correct 5 ms 896 KB Output is correct
24 Correct 5 ms 768 KB Output is correct
25 Correct 5 ms 768 KB Output is correct
26 Correct 5 ms 768 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 896 KB Output is correct
30 Correct 5 ms 896 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 5 ms 768 KB Output is correct
33 Correct 5 ms 896 KB Output is correct
34 Correct 5 ms 896 KB Output is correct
35 Correct 5 ms 896 KB Output is correct
36 Correct 56 ms 54912 KB Output is correct
37 Correct 33 ms 33536 KB Output is correct
38 Correct 17 ms 18176 KB Output is correct
39 Correct 31 ms 31616 KB Output is correct
40 Correct 42 ms 40960 KB Output is correct
41 Correct 17 ms 15488 KB Output is correct
42 Correct 14 ms 12280 KB Output is correct
43 Correct 16 ms 15232 KB Output is correct
44 Correct 8 ms 6016 KB Output is correct
45 Correct 18 ms 15744 KB Output is correct
46 Correct 11 ms 11392 KB Output is correct
47 Correct 16 ms 16128 KB Output is correct
48 Correct 13 ms 12800 KB Output is correct
49 Correct 16 ms 15104 KB Output is correct
50 Correct 9 ms 8192 KB Output is correct
51 Correct 16 ms 15104 KB Output is correct
52 Correct 8 ms 5632 KB Output is correct
53 Correct 13 ms 14848 KB Output is correct
54 Correct 9 ms 7296 KB Output is correct
55 Correct 14 ms 15872 KB Output is correct
56 Correct 10 ms 8832 KB Output is correct
57 Correct 16 ms 16384 KB Output is correct
58 Correct 13 ms 9856 KB Output is correct
59 Correct 74 ms 67576 KB Output is correct
60 Correct 32 ms 45696 KB Output is correct
61 Correct 83 ms 67676 KB Output is correct
62 Correct 31 ms 45184 KB Output is correct
63 Correct 75 ms 67576 KB Output is correct
64 Correct 33 ms 45824 KB Output is correct
65 Correct 56 ms 61048 KB Output is correct
66 Correct 46 ms 56056 KB Output is correct
67 Correct 39 ms 53752 KB Output is correct
68 Correct 36 ms 49664 KB Output is correct
69 Correct 54 ms 60408 KB Output is correct
70 Correct 47 ms 57856 KB Output is correct
71 Correct 41 ms 58488 KB Output is correct
72 Correct 48 ms 59136 KB Output is correct
73 Correct 42 ms 54904 KB Output is correct
74 Correct 42 ms 51328 KB Output is correct
75 Correct 40 ms 56704 KB Output is correct
76 Correct 72 ms 64896 KB Output is correct
77 Correct 46 ms 64888 KB Output is correct
78 Correct 54 ms 50168 KB Output is correct
79 Correct 43 ms 52088 KB Output is correct
80 Correct 73 ms 63608 KB Output is correct
81 Correct 37 ms 52472 KB Output is correct
82 Correct 51 ms 55416 KB Output is correct
83 Correct 48 ms 67576 KB Output is correct
84 Correct 52 ms 57848 KB Output is correct
85 Correct 67 ms 63096 KB Output is correct
86 Correct 56 ms 61688 KB Output is correct
87 Correct 40 ms 56704 KB Output is correct
88 Correct 55 ms 68220 KB Output is correct
89 Correct 48 ms 68224 KB Output is correct
90 Correct 40 ms 57336 KB Output is correct
91 Correct 54 ms 68216 KB Output is correct
92 Correct 49 ms 68216 KB Output is correct
93 Correct 47 ms 66984 KB Output is correct