Submission #733539

# Submission time Handle Problem Language Result Execution time Memory
733539 2023-05-01T02:39:26 Z pcc Collecting Stamps 3 (JOI20_ho_t3) C++14
25 / 100
2000 ms 91392 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;

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;
	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(done[l][r][cnt][dir])continue;
		done[l][r][cnt][dir] = true;
		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(!done[l][nr][rcnt][1])pq.push(make_tuple(rt,l,nr,rcnt,1));
		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(!done[nl][r][lcnt][0])pq.push(make_tuple(lt,nl,r,lcnt,0));
	}
	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 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 906 ms 28048 KB Output is correct
19 Correct 476 ms 15152 KB Output is correct
20 Correct 118 ms 7996 KB Output is correct
21 Correct 359 ms 14896 KB Output is correct
22 Correct 634 ms 26300 KB Output is correct
23 Correct 141 ms 7620 KB Output is correct
24 Correct 37 ms 4716 KB Output is correct
25 Correct 130 ms 7568 KB Output is correct
26 Correct 16 ms 1984 KB Output is correct
27 Correct 156 ms 7680 KB Output is correct
28 Correct 28 ms 4540 KB Output is correct
29 Correct 128 ms 7732 KB Output is correct
30 Correct 37 ms 4804 KB Output is correct
31 Correct 104 ms 7620 KB Output is correct
32 Correct 32 ms 2892 KB Output is correct
33 Correct 84 ms 4920 KB Output is correct
34 Correct 12 ms 2508 KB Output is correct
35 Correct 22 ms 3100 KB Output is correct
36 Correct 16 ms 2764 KB Output is correct
37 Correct 42 ms 3868 KB Output is correct
38 Correct 33 ms 3008 KB Output is correct
39 Correct 37 ms 3924 KB Output is correct
40 Correct 20 ms 3148 KB Output is correct
41 Correct 1611 ms 50160 KB Output is correct
42 Correct 11 ms 6732 KB Output is correct
43 Correct 1579 ms 50132 KB Output is correct
44 Correct 12 ms 6672 KB Output is correct
45 Correct 1545 ms 50092 KB Output is correct
46 Correct 13 ms 6732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 906 ms 28048 KB Output is correct
37 Correct 476 ms 15152 KB Output is correct
38 Correct 118 ms 7996 KB Output is correct
39 Correct 359 ms 14896 KB Output is correct
40 Correct 634 ms 26300 KB Output is correct
41 Correct 141 ms 7620 KB Output is correct
42 Correct 37 ms 4716 KB Output is correct
43 Correct 130 ms 7568 KB Output is correct
44 Correct 16 ms 1984 KB Output is correct
45 Correct 156 ms 7680 KB Output is correct
46 Correct 28 ms 4540 KB Output is correct
47 Correct 128 ms 7732 KB Output is correct
48 Correct 37 ms 4804 KB Output is correct
49 Correct 104 ms 7620 KB Output is correct
50 Correct 32 ms 2892 KB Output is correct
51 Correct 84 ms 4920 KB Output is correct
52 Correct 12 ms 2508 KB Output is correct
53 Correct 22 ms 3100 KB Output is correct
54 Correct 16 ms 2764 KB Output is correct
55 Correct 42 ms 3868 KB Output is correct
56 Correct 33 ms 3008 KB Output is correct
57 Correct 37 ms 3924 KB Output is correct
58 Correct 20 ms 3148 KB Output is correct
59 Correct 1611 ms 50160 KB Output is correct
60 Correct 11 ms 6732 KB Output is correct
61 Correct 1579 ms 50132 KB Output is correct
62 Correct 12 ms 6672 KB Output is correct
63 Correct 1545 ms 50092 KB Output is correct
64 Correct 13 ms 6732 KB Output is correct
65 Correct 1156 ms 49388 KB Output is correct
66 Correct 953 ms 48740 KB Output is correct
67 Correct 845 ms 27888 KB Output is correct
68 Correct 709 ms 27424 KB Output is correct
69 Correct 1184 ms 49300 KB Output is correct
70 Correct 1126 ms 49200 KB Output is correct
71 Correct 850 ms 49068 KB Output is correct
72 Correct 1189 ms 49164 KB Output is correct
73 Correct 413 ms 28192 KB Output is correct
74 Correct 858 ms 27684 KB Output is correct
75 Correct 821 ms 48848 KB Output is correct
76 Correct 1123 ms 49820 KB Output is correct
77 Correct 1149 ms 49800 KB Output is correct
78 Correct 641 ms 27424 KB Output is correct
79 Correct 937 ms 48164 KB Output is correct
80 Correct 1065 ms 49704 KB Output is correct
81 Correct 840 ms 48288 KB Output is correct
82 Correct 417 ms 28192 KB Output is correct
83 Correct 1162 ms 50184 KB Output is correct
84 Correct 395 ms 28524 KB Output is correct
85 Correct 571 ms 49672 KB Output is correct
86 Correct 494 ms 28904 KB Output is correct
87 Correct 1002 ms 48772 KB Output is correct
88 Execution timed out 2016 ms 91392 KB Time limit exceeded
89 Halted 0 ms 0 KB -