답안 #361599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361599 2021-01-30T18:58:30 Z saarang123 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
167 ms 134764 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 207;
const int inf = 1e18;
int dp[N][N][2][N]; //no (l, r), side, stamps
int x[N], t[N];
int n, m;
signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    	cin >> x[i];
    x[n + 1] = m;
    for(int i = 1; i <= n; i++)
    	cin >> t[i];
    for(int i = 0; i <= n + 2; i++)
    	for(int j = 0; j <= n + 2; j++)
    		for(int k = 0; k < 2; k++)
    			for(int l = 0; l <= n + 2; l++)
    				dp[i][j][k][l] = inf;
    dp[0][n + 1][0][0] = dp[0][n + 1][1][0] = 0;
    for(int i = 0; i < n; i++) {
    	for(int j = n + 1; j > i + 1; j--) {
    		for(int k = 0; k <= n; k++) {
    			int time = min(dp[i][j][0][k] + (x[i + 1] - x[i]), dp[i][j][1][k] + (m - x[j] + x[i + 1]));  //include i
    			dp[i + 1][j][0][k + (time <= t[i + 1])] = min(dp[i + 1][j][0][k + (time <= t[i + 1])], time);
    			time = min(dp[i][j][0][k] + (m - x[j - 1] + x[i]), dp[i][j][1][k] + (x[j] - x[j - 1]));
    			dp[i][j - 1][1][k + (time <= t[j - 1])] = min(dp[i][j - 1][1][k + (time <= t[j - 1])], time); //include j
    		}
    	}
    }
    int ans = 0;
    for(int i = 0; i <= n + 1; i++)
    	for(int j = 0; j <= n + 1; j++)
    		for(int k = 0; k < 2; k++)
    			for(int l = 0; l <= n; l++)
    				if(dp[i][j][k][l] != inf)
    					ans = max(ans, l);
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Correct 1 ms 1388 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 1132 KB Output is correct
21 Correct 1 ms 1388 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 1516 KB Output is correct
24 Correct 1 ms 1260 KB Output is correct
25 Correct 1 ms 1388 KB Output is correct
26 Correct 1 ms 1388 KB Output is correct
27 Correct 1 ms 748 KB Output is correct
28 Correct 1 ms 876 KB Output is correct
29 Correct 1 ms 1516 KB Output is correct
30 Correct 1 ms 1516 KB Output is correct
31 Correct 1 ms 1296 KB Output is correct
32 Correct 1 ms 1260 KB Output is correct
33 Correct 1 ms 1516 KB Output is correct
34 Correct 1 ms 1516 KB Output is correct
35 Correct 2 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Correct 125 ms 108396 KB Output is correct
19 Correct 69 ms 66284 KB Output is correct
20 Correct 36 ms 35820 KB Output is correct
21 Correct 65 ms 62572 KB Output is correct
22 Correct 101 ms 80876 KB Output is correct
23 Correct 30 ms 30572 KB Output is correct
24 Correct 22 ms 24044 KB Output is correct
25 Correct 29 ms 29932 KB Output is correct
26 Correct 10 ms 11884 KB Output is correct
27 Correct 30 ms 31212 KB Output is correct
28 Correct 22 ms 22528 KB Output is correct
29 Correct 30 ms 31852 KB Output is correct
30 Correct 23 ms 25196 KB Output is correct
31 Correct 28 ms 29932 KB Output is correct
32 Correct 15 ms 15980 KB Output is correct
33 Correct 29 ms 29932 KB Output is correct
34 Correct 9 ms 11116 KB Output is correct
35 Correct 27 ms 29292 KB Output is correct
36 Correct 13 ms 14316 KB Output is correct
37 Correct 30 ms 31212 KB Output is correct
38 Correct 15 ms 17388 KB Output is correct
39 Correct 31 ms 32492 KB Output is correct
40 Correct 17 ms 19308 KB Output is correct
41 Correct 160 ms 133356 KB Output is correct
42 Correct 97 ms 90348 KB Output is correct
43 Correct 161 ms 133356 KB Output is correct
44 Correct 97 ms 89196 KB Output is correct
45 Correct 162 ms 133612 KB Output is correct
46 Correct 98 ms 90348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 1132 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Correct 1 ms 1388 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 1132 KB Output is correct
21 Correct 1 ms 1388 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 1516 KB Output is correct
24 Correct 1 ms 1260 KB Output is correct
25 Correct 1 ms 1388 KB Output is correct
26 Correct 1 ms 1388 KB Output is correct
27 Correct 1 ms 748 KB Output is correct
28 Correct 1 ms 876 KB Output is correct
29 Correct 1 ms 1516 KB Output is correct
30 Correct 1 ms 1516 KB Output is correct
31 Correct 1 ms 1296 KB Output is correct
32 Correct 1 ms 1260 KB Output is correct
33 Correct 1 ms 1516 KB Output is correct
34 Correct 1 ms 1516 KB Output is correct
35 Correct 2 ms 1516 KB Output is correct
36 Correct 125 ms 108396 KB Output is correct
37 Correct 69 ms 66284 KB Output is correct
38 Correct 36 ms 35820 KB Output is correct
39 Correct 65 ms 62572 KB Output is correct
40 Correct 101 ms 80876 KB Output is correct
41 Correct 30 ms 30572 KB Output is correct
42 Correct 22 ms 24044 KB Output is correct
43 Correct 29 ms 29932 KB Output is correct
44 Correct 10 ms 11884 KB Output is correct
45 Correct 30 ms 31212 KB Output is correct
46 Correct 22 ms 22528 KB Output is correct
47 Correct 30 ms 31852 KB Output is correct
48 Correct 23 ms 25196 KB Output is correct
49 Correct 28 ms 29932 KB Output is correct
50 Correct 15 ms 15980 KB Output is correct
51 Correct 29 ms 29932 KB Output is correct
52 Correct 9 ms 11116 KB Output is correct
53 Correct 27 ms 29292 KB Output is correct
54 Correct 13 ms 14316 KB Output is correct
55 Correct 30 ms 31212 KB Output is correct
56 Correct 15 ms 17388 KB Output is correct
57 Correct 31 ms 32492 KB Output is correct
58 Correct 17 ms 19308 KB Output is correct
59 Correct 160 ms 133356 KB Output is correct
60 Correct 97 ms 90348 KB Output is correct
61 Correct 161 ms 133356 KB Output is correct
62 Correct 97 ms 89196 KB Output is correct
63 Correct 162 ms 133612 KB Output is correct
64 Correct 98 ms 90348 KB Output is correct
65 Correct 141 ms 120684 KB Output is correct
66 Correct 120 ms 110828 KB Output is correct
67 Correct 119 ms 106092 KB Output is correct
68 Correct 108 ms 98156 KB Output is correct
69 Correct 147 ms 119276 KB Output is correct
70 Correct 130 ms 114412 KB Output is correct
71 Correct 140 ms 115564 KB Output is correct
72 Correct 135 ms 116844 KB Output is correct
73 Correct 125 ms 108416 KB Output is correct
74 Correct 114 ms 101356 KB Output is correct
75 Correct 125 ms 111980 KB Output is correct
76 Correct 153 ms 128236 KB Output is correct
77 Correct 158 ms 128328 KB Output is correct
78 Correct 119 ms 99180 KB Output is correct
79 Correct 113 ms 102636 KB Output is correct
80 Correct 149 ms 125676 KB Output is correct
81 Correct 116 ms 103788 KB Output is correct
82 Correct 124 ms 109548 KB Output is correct
83 Correct 158 ms 133356 KB Output is correct
84 Correct 132 ms 114412 KB Output is correct
85 Correct 145 ms 124396 KB Output is correct
86 Correct 149 ms 121884 KB Output is correct
87 Correct 133 ms 111980 KB Output is correct
88 Correct 162 ms 134764 KB Output is correct
89 Correct 162 ms 134636 KB Output is correct
90 Correct 128 ms 113132 KB Output is correct
91 Correct 167 ms 134636 KB Output is correct
92 Correct 160 ms 134636 KB Output is correct
93 Correct 166 ms 132076 KB Output is correct