Submission #733541

# Submission time Handle Problem Language Result Execution time Memory
733541 2023-05-01T02:44:01 Z pcc Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
1739 ms 170568 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second

const ll mxn = 202;
ll dp[mxn][mxn][mxn][2];
bool done[mxn][mxn][mxn][2];
pll arr[mxn];
priority_queue<tuple<ll,ll,ll,ll,ll>,vector<tuple<ll,ll,ll,ll,ll>>,greater<tuple<ll,ll,ll,ll,ll>>> pq;
ll n,L;
const ll inf = 1e9+10;

ll calc(ll s,ll e,ll dir){
	if(dir){
		return (e+L-s)%(L);
	}
	else{
		return L-(e+L-s)%L;
	}
}

void solve(){
	cin>>n>>L;
	for(int i = 1;i<=n;i++)cin>>arr[i].fs;
	for(int i = 1;i<=n;i++)cin>>arr[i].sc;
	for(auto &i:dp)for(auto &j:i)for(auto &k:j)for(auto &l:k)l = inf;
	arr[0] = {0,0};
	dp[0][0][0][0] = 0;
	pq.push(make_tuple(0,0,0,0,0));
	ll ans = 0;
	while(!pq.empty()){
		ll val = get<0>(pq.top()),l = get<1>(pq.top()),r = get<2>(pq.top());
		ll cnt = get<3>(pq.top()),dir = get<4>(pq.top());
		//cout<<val<<' '<<l<<' '<<r<<' '<<cnt<<' '<<dir<<endl;
		pq.pop();
		if(dp[l][r][cnt][dir] != val)continue;
		if((r+1)%(n+1) == l){
			ans = max(ans,cnt);
			continue;
		}
		ll pos = (dir?arr[r].fs:arr[l].fs);
		int nr = r+1;
		if(nr>=n+1)nr -= n+1;
		int nl = l-1;
		if(nl<0)nl += n+1;
		ll rt = val+calc(pos,arr[nr].fs,1);
		ll rcnt = cnt + (rt<=arr[nr].sc?1:0);
		if(dp[l][nr][rcnt][1] > rt)pq.push(make_tuple(rt,l,nr,rcnt,1)),dp[l][nr][rcnt][1] = rt;
		ll lt = val+calc(pos,arr[nl].fs,0);
		ll lcnt = cnt+(lt<=arr[nl].sc?1:0);
		//cout<<l<<','<<r<<','<<dir<<','<<pos<<lt<<','<<lcnt<<','<<','<<nl<<endl;
		if(dp[nl][r][lcnt][0] > lt)pq.push(make_tuple(lt,nl,r,lcnt,0)),dp[nl][r][lcnt][0] = lt;
	}
	cout<<ans;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	while(t--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 51 ms 129228 KB Output is correct
2 Correct 51 ms 129228 KB Output is correct
3 Correct 52 ms 129268 KB Output is correct
4 Correct 51 ms 129228 KB Output is correct
5 Correct 52 ms 129264 KB Output is correct
6 Correct 63 ms 129300 KB Output is correct
7 Correct 53 ms 129252 KB Output is correct
8 Correct 52 ms 129292 KB Output is correct
9 Correct 51 ms 129356 KB Output is correct
10 Correct 51 ms 129348 KB Output is correct
11 Correct 52 ms 129376 KB Output is correct
12 Correct 54 ms 129308 KB Output is correct
13 Correct 53 ms 129356 KB Output is correct
14 Correct 55 ms 129228 KB Output is correct
15 Correct 53 ms 129356 KB Output is correct
16 Correct 52 ms 129228 KB Output is correct
17 Correct 51 ms 129332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 129228 KB Output is correct
2 Correct 51 ms 129228 KB Output is correct
3 Correct 52 ms 129268 KB Output is correct
4 Correct 51 ms 129228 KB Output is correct
5 Correct 52 ms 129264 KB Output is correct
6 Correct 63 ms 129300 KB Output is correct
7 Correct 53 ms 129252 KB Output is correct
8 Correct 52 ms 129292 KB Output is correct
9 Correct 51 ms 129356 KB Output is correct
10 Correct 51 ms 129348 KB Output is correct
11 Correct 52 ms 129376 KB Output is correct
12 Correct 54 ms 129308 KB Output is correct
13 Correct 53 ms 129356 KB Output is correct
14 Correct 55 ms 129228 KB Output is correct
15 Correct 53 ms 129356 KB Output is correct
16 Correct 52 ms 129228 KB Output is correct
17 Correct 51 ms 129332 KB Output is correct
18 Correct 54 ms 129280 KB Output is correct
19 Correct 51 ms 129284 KB Output is correct
20 Correct 51 ms 129344 KB Output is correct
21 Correct 51 ms 129344 KB Output is correct
22 Correct 51 ms 129356 KB Output is correct
23 Correct 52 ms 129332 KB Output is correct
24 Correct 53 ms 129344 KB Output is correct
25 Correct 55 ms 129356 KB Output is correct
26 Correct 66 ms 129340 KB Output is correct
27 Correct 52 ms 129280 KB Output is correct
28 Correct 58 ms 129264 KB Output is correct
29 Correct 53 ms 129224 KB Output is correct
30 Correct 52 ms 129228 KB Output is correct
31 Correct 52 ms 129320 KB Output is correct
32 Correct 55 ms 129300 KB Output is correct
33 Correct 52 ms 129368 KB Output is correct
34 Correct 55 ms 129360 KB Output is correct
35 Correct 54 ms 129280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 129228 KB Output is correct
2 Correct 51 ms 129228 KB Output is correct
3 Correct 52 ms 129268 KB Output is correct
4 Correct 51 ms 129228 KB Output is correct
5 Correct 52 ms 129264 KB Output is correct
6 Correct 63 ms 129300 KB Output is correct
7 Correct 53 ms 129252 KB Output is correct
8 Correct 52 ms 129292 KB Output is correct
9 Correct 51 ms 129356 KB Output is correct
10 Correct 51 ms 129348 KB Output is correct
11 Correct 52 ms 129376 KB Output is correct
12 Correct 54 ms 129308 KB Output is correct
13 Correct 53 ms 129356 KB Output is correct
14 Correct 55 ms 129228 KB Output is correct
15 Correct 53 ms 129356 KB Output is correct
16 Correct 52 ms 129228 KB Output is correct
17 Correct 51 ms 129332 KB Output is correct
18 Correct 992 ms 150036 KB Output is correct
19 Correct 456 ms 139696 KB Output is correct
20 Correct 158 ms 134544 KB Output is correct
21 Correct 368 ms 139752 KB Output is correct
22 Correct 732 ms 150136 KB Output is correct
23 Correct 176 ms 134632 KB Output is correct
24 Correct 87 ms 131944 KB Output is correct
25 Correct 155 ms 134544 KB Output is correct
26 Correct 64 ms 130056 KB Output is correct
27 Correct 178 ms 134532 KB Output is correct
28 Correct 81 ms 132032 KB Output is correct
29 Correct 161 ms 134560 KB Output is correct
30 Correct 89 ms 132012 KB Output is correct
31 Correct 150 ms 134660 KB Output is correct
32 Correct 84 ms 130684 KB Output is correct
33 Correct 146 ms 132172 KB Output is correct
34 Correct 61 ms 130740 KB Output is correct
35 Correct 72 ms 130088 KB Output is correct
36 Correct 66 ms 130704 KB Output is correct
37 Correct 78 ms 130676 KB Output is correct
38 Correct 84 ms 130668 KB Output is correct
39 Correct 80 ms 130740 KB Output is correct
40 Correct 71 ms 130676 KB Output is correct
41 Correct 1664 ms 170568 KB Output is correct
42 Correct 60 ms 130016 KB Output is correct
43 Correct 1739 ms 170428 KB Output is correct
44 Correct 63 ms 129808 KB Output is correct
45 Correct 1726 ms 170512 KB Output is correct
46 Correct 60 ms 130056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 129228 KB Output is correct
2 Correct 51 ms 129228 KB Output is correct
3 Correct 52 ms 129268 KB Output is correct
4 Correct 51 ms 129228 KB Output is correct
5 Correct 52 ms 129264 KB Output is correct
6 Correct 63 ms 129300 KB Output is correct
7 Correct 53 ms 129252 KB Output is correct
8 Correct 52 ms 129292 KB Output is correct
9 Correct 51 ms 129356 KB Output is correct
10 Correct 51 ms 129348 KB Output is correct
11 Correct 52 ms 129376 KB Output is correct
12 Correct 54 ms 129308 KB Output is correct
13 Correct 53 ms 129356 KB Output is correct
14 Correct 55 ms 129228 KB Output is correct
15 Correct 53 ms 129356 KB Output is correct
16 Correct 52 ms 129228 KB Output is correct
17 Correct 51 ms 129332 KB Output is correct
18 Correct 54 ms 129280 KB Output is correct
19 Correct 51 ms 129284 KB Output is correct
20 Correct 51 ms 129344 KB Output is correct
21 Correct 51 ms 129344 KB Output is correct
22 Correct 51 ms 129356 KB Output is correct
23 Correct 52 ms 129332 KB Output is correct
24 Correct 53 ms 129344 KB Output is correct
25 Correct 55 ms 129356 KB Output is correct
26 Correct 66 ms 129340 KB Output is correct
27 Correct 52 ms 129280 KB Output is correct
28 Correct 58 ms 129264 KB Output is correct
29 Correct 53 ms 129224 KB Output is correct
30 Correct 52 ms 129228 KB Output is correct
31 Correct 52 ms 129320 KB Output is correct
32 Correct 55 ms 129300 KB Output is correct
33 Correct 52 ms 129368 KB Output is correct
34 Correct 55 ms 129360 KB Output is correct
35 Correct 54 ms 129280 KB Output is correct
36 Correct 992 ms 150036 KB Output is correct
37 Correct 456 ms 139696 KB Output is correct
38 Correct 158 ms 134544 KB Output is correct
39 Correct 368 ms 139752 KB Output is correct
40 Correct 732 ms 150136 KB Output is correct
41 Correct 176 ms 134632 KB Output is correct
42 Correct 87 ms 131944 KB Output is correct
43 Correct 155 ms 134544 KB Output is correct
44 Correct 64 ms 130056 KB Output is correct
45 Correct 178 ms 134532 KB Output is correct
46 Correct 81 ms 132032 KB Output is correct
47 Correct 161 ms 134560 KB Output is correct
48 Correct 89 ms 132012 KB Output is correct
49 Correct 150 ms 134660 KB Output is correct
50 Correct 84 ms 130684 KB Output is correct
51 Correct 146 ms 132172 KB Output is correct
52 Correct 61 ms 130740 KB Output is correct
53 Correct 72 ms 130088 KB Output is correct
54 Correct 66 ms 130704 KB Output is correct
55 Correct 78 ms 130676 KB Output is correct
56 Correct 84 ms 130668 KB Output is correct
57 Correct 80 ms 130740 KB Output is correct
58 Correct 71 ms 130676 KB Output is correct
59 Correct 1664 ms 170568 KB Output is correct
60 Correct 60 ms 130016 KB Output is correct
61 Correct 1739 ms 170428 KB Output is correct
62 Correct 63 ms 129808 KB Output is correct
63 Correct 1726 ms 170512 KB Output is correct
64 Correct 60 ms 130056 KB Output is correct
65 Correct 94 ms 130664 KB Output is correct
66 Correct 90 ms 130684 KB Output is correct
67 Correct 88 ms 130200 KB Output is correct
68 Correct 80 ms 130056 KB Output is correct
69 Correct 91 ms 130740 KB Output is correct
70 Correct 145 ms 132052 KB Output is correct
71 Correct 58 ms 129372 KB Output is correct
72 Correct 148 ms 130872 KB Output is correct
73 Correct 54 ms 129312 KB Output is correct
74 Correct 143 ms 132024 KB Output is correct
75 Correct 56 ms 129492 KB Output is correct
76 Correct 448 ms 134596 KB Output is correct
77 Correct 59 ms 129580 KB Output is correct
78 Correct 281 ms 131996 KB Output is correct
79 Correct 74 ms 130144 KB Output is correct
80 Correct 417 ms 134616 KB Output is correct
81 Correct 57 ms 129496 KB Output is correct
82 Correct 238 ms 134612 KB Output is correct
83 Correct 69 ms 129708 KB Output is correct
84 Correct 255 ms 134572 KB Output is correct
85 Correct 57 ms 129368 KB Output is correct
86 Correct 296 ms 134584 KB Output is correct
87 Correct 77 ms 130056 KB Output is correct
88 Correct 118 ms 130772 KB Output is correct
89 Correct 69 ms 129800 KB Output is correct
90 Correct 59 ms 129604 KB Output is correct
91 Correct 130 ms 130736 KB Output is correct
92 Correct 67 ms 129732 KB Output is correct
93 Correct 64 ms 129676 KB Output is correct