# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
959251 | 2024-04-07T18:21:14 Z | AndreiBOTO | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 241 ms | 445008 KB |
#include <bits/stdc++.h> #pragma optimize GCC ("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") ///#include <tryhardmode> ///#include <GODMODE::ON> using namespace std; ///What a day... ///You look lonely, I can fix that const long long INF=1e13; const int NMAX=305; #define int long long int dp[NMAX][NMAX][NMAX][2]; ///minimum time -> clock, counter-clock, answer, direction (0->clock, 1->counter-clock) int x[NMAX]; int t[NMAX]; int l; int get_dist(int a,int b) { ///I got guns in my head and they won't go, ///Spirits in my head and they won't go... if(a==b) return 0; else { if(a>b) swap(a,b); return min(x[b]-x[a],l-x[b]+x[a]); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,i,j,k,st,dr,ans,best=0; cin>>n>>l; for(i=1;i<=n;i++) cin>>x[i]; x[0]=0; x[n+1]=l; for(i=1;i<=n;i++) cin>>t[i]; t[0]=-1; t[n+1]=-1; /*for(i=0;i<=n+1;i++) for(j=0;j<=n+1;j++) for(k=0;k<=n+1;k++) dp[i][j][k][0]=dp[i][j][k][1]=INF;*/ memset(dp,63,sizeof(dp)); dp[0][0][0][0]=dp[0][0][0][1]=0; for(st=0;st<=n;st++) { for(dr=0;dr<=n;dr++) { if(st+dr>n) break; for(ans=0;ans<=n;ans++) { if(min(dp[st][dr][ans][0],dp[st][dr][ans][1])<INF) best=max(best,ans); if(st+1<=n) { long long auxy=dp[st][dr][ans][1]+get_dist(n+1-dr,st+1); auxy=min(auxy,dp[st][dr][ans][0]+get_dist(st,st+1)); if(auxy<=t[st+1]) dp[st+1][dr][ans+1][0]=min(dp[st+1][dr][ans+1][0],auxy); else dp[st+1][dr][ans][0]=min(dp[st+1][dr][ans][0],auxy); } if(dr+1<=n) { long long auxy=dp[st][dr][ans][1]+get_dist(n+1-dr,n+1-dr-1); auxy=min(auxy,dp[st][dr][ans][0]+get_dist(st,n+1-dr-1)); if(auxy<=t[n+1-dr-1]) dp[st][dr+1][ans+1][1]=min(dp[st][dr+1][ans+1][1],auxy); else dp[st][dr+1][ans][1]=min(dp[st][dr+1][ans][1],auxy); } } } } cout<<best<<"\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 444752 KB | Output is correct |
2 | Correct | 114 ms | 444484 KB | Output is correct |
3 | Correct | 115 ms | 444500 KB | Output is correct |
4 | Correct | 114 ms | 444460 KB | Output is correct |
5 | Correct | 117 ms | 444796 KB | Output is correct |
6 | Correct | 112 ms | 444404 KB | Output is correct |
7 | Correct | 113 ms | 444496 KB | Output is correct |
8 | Correct | 116 ms | 444576 KB | Output is correct |
9 | Correct | 116 ms | 444592 KB | Output is correct |
10 | Correct | 120 ms | 444596 KB | Output is correct |
11 | Correct | 115 ms | 444528 KB | Output is correct |
12 | Correct | 114 ms | 444500 KB | Output is correct |
13 | Correct | 115 ms | 444480 KB | Output is correct |
14 | Correct | 114 ms | 444496 KB | Output is correct |
15 | Correct | 114 ms | 444452 KB | Output is correct |
16 | Correct | 123 ms | 444596 KB | Output is correct |
17 | Correct | 114 ms | 444388 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 444752 KB | Output is correct |
2 | Correct | 114 ms | 444484 KB | Output is correct |
3 | Correct | 115 ms | 444500 KB | Output is correct |
4 | Correct | 114 ms | 444460 KB | Output is correct |
5 | Correct | 117 ms | 444796 KB | Output is correct |
6 | Correct | 112 ms | 444404 KB | Output is correct |
7 | Correct | 113 ms | 444496 KB | Output is correct |
8 | Correct | 116 ms | 444576 KB | Output is correct |
9 | Correct | 116 ms | 444592 KB | Output is correct |
10 | Correct | 120 ms | 444596 KB | Output is correct |
11 | Correct | 115 ms | 444528 KB | Output is correct |
12 | Correct | 114 ms | 444500 KB | Output is correct |
13 | Correct | 115 ms | 444480 KB | Output is correct |
14 | Correct | 114 ms | 444496 KB | Output is correct |
15 | Correct | 114 ms | 444452 KB | Output is correct |
16 | Correct | 123 ms | 444596 KB | Output is correct |
17 | Correct | 114 ms | 444388 KB | Output is correct |
18 | Correct | 117 ms | 444384 KB | Output is correct |
19 | Correct | 113 ms | 444532 KB | Output is correct |
20 | Correct | 115 ms | 444520 KB | Output is correct |
21 | Correct | 112 ms | 444568 KB | Output is correct |
22 | Correct | 114 ms | 444440 KB | Output is correct |
23 | Correct | 112 ms | 444496 KB | Output is correct |
24 | Correct | 118 ms | 444472 KB | Output is correct |
25 | Correct | 113 ms | 444496 KB | Output is correct |
26 | Correct | 118 ms | 444500 KB | Output is correct |
27 | Correct | 115 ms | 444496 KB | Output is correct |
28 | Correct | 118 ms | 444856 KB | Output is correct |
29 | Correct | 113 ms | 444496 KB | Output is correct |
30 | Correct | 113 ms | 444500 KB | Output is correct |
31 | Correct | 113 ms | 444640 KB | Output is correct |
32 | Correct | 114 ms | 444596 KB | Output is correct |
33 | Correct | 112 ms | 444428 KB | Output is correct |
34 | Correct | 114 ms | 444496 KB | Output is correct |
35 | Correct | 113 ms | 444496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 444752 KB | Output is correct |
2 | Correct | 114 ms | 444484 KB | Output is correct |
3 | Correct | 115 ms | 444500 KB | Output is correct |
4 | Correct | 114 ms | 444460 KB | Output is correct |
5 | Correct | 117 ms | 444796 KB | Output is correct |
6 | Correct | 112 ms | 444404 KB | Output is correct |
7 | Correct | 113 ms | 444496 KB | Output is correct |
8 | Correct | 116 ms | 444576 KB | Output is correct |
9 | Correct | 116 ms | 444592 KB | Output is correct |
10 | Correct | 120 ms | 444596 KB | Output is correct |
11 | Correct | 115 ms | 444528 KB | Output is correct |
12 | Correct | 114 ms | 444500 KB | Output is correct |
13 | Correct | 115 ms | 444480 KB | Output is correct |
14 | Correct | 114 ms | 444496 KB | Output is correct |
15 | Correct | 114 ms | 444452 KB | Output is correct |
16 | Correct | 123 ms | 444596 KB | Output is correct |
17 | Correct | 114 ms | 444388 KB | Output is correct |
18 | Correct | 139 ms | 444756 KB | Output is correct |
19 | Correct | 125 ms | 444484 KB | Output is correct |
20 | Correct | 125 ms | 444496 KB | Output is correct |
21 | Correct | 124 ms | 444756 KB | Output is correct |
22 | Correct | 138 ms | 444496 KB | Output is correct |
23 | Correct | 118 ms | 444468 KB | Output is correct |
24 | Correct | 117 ms | 444500 KB | Output is correct |
25 | Correct | 128 ms | 444672 KB | Output is correct |
26 | Correct | 115 ms | 444588 KB | Output is correct |
27 | Correct | 117 ms | 444500 KB | Output is correct |
28 | Correct | 119 ms | 444496 KB | Output is correct |
29 | Correct | 125 ms | 444572 KB | Output is correct |
30 | Correct | 119 ms | 444556 KB | Output is correct |
31 | Correct | 119 ms | 444412 KB | Output is correct |
32 | Correct | 118 ms | 444752 KB | Output is correct |
33 | Correct | 118 ms | 444500 KB | Output is correct |
34 | Correct | 114 ms | 444484 KB | Output is correct |
35 | Correct | 117 ms | 444392 KB | Output is correct |
36 | Correct | 114 ms | 444496 KB | Output is correct |
37 | Correct | 120 ms | 444496 KB | Output is correct |
38 | Correct | 124 ms | 444508 KB | Output is correct |
39 | Correct | 118 ms | 444752 KB | Output is correct |
40 | Correct | 115 ms | 444500 KB | Output is correct |
41 | Correct | 144 ms | 444496 KB | Output is correct |
42 | Correct | 135 ms | 444500 KB | Output is correct |
43 | Correct | 151 ms | 444648 KB | Output is correct |
44 | Correct | 144 ms | 444496 KB | Output is correct |
45 | Correct | 145 ms | 444500 KB | Output is correct |
46 | Correct | 133 ms | 444500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 444752 KB | Output is correct |
2 | Correct | 114 ms | 444484 KB | Output is correct |
3 | Correct | 115 ms | 444500 KB | Output is correct |
4 | Correct | 114 ms | 444460 KB | Output is correct |
5 | Correct | 117 ms | 444796 KB | Output is correct |
6 | Correct | 112 ms | 444404 KB | Output is correct |
7 | Correct | 113 ms | 444496 KB | Output is correct |
8 | Correct | 116 ms | 444576 KB | Output is correct |
9 | Correct | 116 ms | 444592 KB | Output is correct |
10 | Correct | 120 ms | 444596 KB | Output is correct |
11 | Correct | 115 ms | 444528 KB | Output is correct |
12 | Correct | 114 ms | 444500 KB | Output is correct |
13 | Correct | 115 ms | 444480 KB | Output is correct |
14 | Correct | 114 ms | 444496 KB | Output is correct |
15 | Correct | 114 ms | 444452 KB | Output is correct |
16 | Correct | 123 ms | 444596 KB | Output is correct |
17 | Correct | 114 ms | 444388 KB | Output is correct |
18 | Correct | 117 ms | 444384 KB | Output is correct |
19 | Correct | 113 ms | 444532 KB | Output is correct |
20 | Correct | 115 ms | 444520 KB | Output is correct |
21 | Correct | 112 ms | 444568 KB | Output is correct |
22 | Correct | 114 ms | 444440 KB | Output is correct |
23 | Correct | 112 ms | 444496 KB | Output is correct |
24 | Correct | 118 ms | 444472 KB | Output is correct |
25 | Correct | 113 ms | 444496 KB | Output is correct |
26 | Correct | 118 ms | 444500 KB | Output is correct |
27 | Correct | 115 ms | 444496 KB | Output is correct |
28 | Correct | 118 ms | 444856 KB | Output is correct |
29 | Correct | 113 ms | 444496 KB | Output is correct |
30 | Correct | 113 ms | 444500 KB | Output is correct |
31 | Correct | 113 ms | 444640 KB | Output is correct |
32 | Correct | 114 ms | 444596 KB | Output is correct |
33 | Correct | 112 ms | 444428 KB | Output is correct |
34 | Correct | 114 ms | 444496 KB | Output is correct |
35 | Correct | 113 ms | 444496 KB | Output is correct |
36 | Correct | 139 ms | 444756 KB | Output is correct |
37 | Correct | 125 ms | 444484 KB | Output is correct |
38 | Correct | 125 ms | 444496 KB | Output is correct |
39 | Correct | 124 ms | 444756 KB | Output is correct |
40 | Correct | 138 ms | 444496 KB | Output is correct |
41 | Correct | 118 ms | 444468 KB | Output is correct |
42 | Correct | 117 ms | 444500 KB | Output is correct |
43 | Correct | 128 ms | 444672 KB | Output is correct |
44 | Correct | 115 ms | 444588 KB | Output is correct |
45 | Correct | 117 ms | 444500 KB | Output is correct |
46 | Correct | 119 ms | 444496 KB | Output is correct |
47 | Correct | 125 ms | 444572 KB | Output is correct |
48 | Correct | 119 ms | 444556 KB | Output is correct |
49 | Correct | 119 ms | 444412 KB | Output is correct |
50 | Correct | 118 ms | 444752 KB | Output is correct |
51 | Correct | 118 ms | 444500 KB | Output is correct |
52 | Correct | 114 ms | 444484 KB | Output is correct |
53 | Correct | 117 ms | 444392 KB | Output is correct |
54 | Correct | 114 ms | 444496 KB | Output is correct |
55 | Correct | 120 ms | 444496 KB | Output is correct |
56 | Correct | 124 ms | 444508 KB | Output is correct |
57 | Correct | 118 ms | 444752 KB | Output is correct |
58 | Correct | 115 ms | 444500 KB | Output is correct |
59 | Correct | 144 ms | 444496 KB | Output is correct |
60 | Correct | 135 ms | 444500 KB | Output is correct |
61 | Correct | 151 ms | 444648 KB | Output is correct |
62 | Correct | 144 ms | 444496 KB | Output is correct |
63 | Correct | 145 ms | 444500 KB | Output is correct |
64 | Correct | 133 ms | 444500 KB | Output is correct |
65 | Correct | 139 ms | 444424 KB | Output is correct |
66 | Correct | 137 ms | 444500 KB | Output is correct |
67 | Correct | 137 ms | 444548 KB | Output is correct |
68 | Correct | 134 ms | 444496 KB | Output is correct |
69 | Correct | 141 ms | 444620 KB | Output is correct |
70 | Correct | 138 ms | 444516 KB | Output is correct |
71 | Correct | 144 ms | 444448 KB | Output is correct |
72 | Correct | 161 ms | 444752 KB | Output is correct |
73 | Correct | 137 ms | 444500 KB | Output is correct |
74 | Correct | 139 ms | 444632 KB | Output is correct |
75 | Correct | 138 ms | 444800 KB | Output is correct |
76 | Correct | 147 ms | 444500 KB | Output is correct |
77 | Correct | 143 ms | 444400 KB | Output is correct |
78 | Correct | 132 ms | 444500 KB | Output is correct |
79 | Correct | 139 ms | 444592 KB | Output is correct |
80 | Correct | 144 ms | 444500 KB | Output is correct |
81 | Correct | 136 ms | 444628 KB | Output is correct |
82 | Correct | 145 ms | 445008 KB | Output is correct |
83 | Correct | 144 ms | 444460 KB | Output is correct |
84 | Correct | 145 ms | 444436 KB | Output is correct |
85 | Correct | 145 ms | 444524 KB | Output is correct |
86 | Correct | 145 ms | 444636 KB | Output is correct |
87 | Correct | 153 ms | 444500 KB | Output is correct |
88 | Correct | 159 ms | 444496 KB | Output is correct |
89 | Correct | 147 ms | 444752 KB | Output is correct |
90 | Correct | 139 ms | 444496 KB | Output is correct |
91 | Correct | 144 ms | 444752 KB | Output is correct |
92 | Correct | 145 ms | 444560 KB | Output is correct |
93 | Correct | 157 ms | 444496 KB | Output is correct |