Submission #624804

# Submission time Handle Problem Language Result Execution time Memory
624804 2022-08-08T18:35:38 Z CSQ31 Abduction 2 (JOI17_abduction2) C++17
44 / 100
1128 ms 14836 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int,int> pii;
typedef long long int ll;
const int MAXN = 55555;
int a[MAXN],b[MAXN];
ll h,w,q;
map<int,ll>dp[2][MAXN];
ll solve(ll i,ll j,ll k){
	if(dp[k][i].find(j) != dp[k][i].end())return dp[k][i][j];
	dp[k][i][j] = -1e9;
	if(!k){
		for(ll jj=j+1;jj<w;jj++){
			if(b[jj] > a[i]){
				dp[0][i][j] = max(dp[0][i][j],solve(i,jj,1) + jj - j);
				break;
			}
		}
		for(ll jj=j-1;jj>=0;jj--){
			if(b[jj] > a[i]){
				dp[0][i][j] = max(dp[0][i][j],solve(i,jj,1) + j - jj);
				break;
			}
		}
		if(dp[0][i][j] == -1e9)dp[0][i][j] = max(w-1-j,j);
	}else{
		for(ll ii=i+1;ii<h;ii++){
			if(a[ii] > b[j]){
				dp[1][i][j] = max(dp[1][i][j],solve(ii,j,0) + ii - i);
				break;
			}
		}
		for(ll ii=i-1;ii>=0;ii--){
			if(a[ii] > b[j]){
				dp[1][i][j] = max(dp[1][i][j],solve(ii,j,0) + i - ii);
				break;
			}
		}
		if(dp[1][i][j] == -1e9)dp[1][i][j] = max(h-1-i,i);
	}
	return dp[k][i][j];
}
int main()
{
	owo
	cin>>h>>w>>q;
	for(int i=0;i<h;i++)cin>>a[i];
	for(int i=0;i<w;i++)cin>>b[i];
	while(q--){
		int i,j;
		cin>>i>>j;
		i--;
		j--;
		ll ans = max(solve(i,j,0),solve(i,j,1));
		cout<<ans<<'\n';
	}
	
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 3 ms 5460 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 3 ms 5460 KB Output is correct
6 Correct 3 ms 5460 KB Output is correct
7 Correct 3 ms 5460 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 3 ms 5460 KB Output is correct
10 Correct 3 ms 5460 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 3 ms 5460 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 3 ms 5460 KB Output is correct
6 Correct 3 ms 5460 KB Output is correct
7 Correct 3 ms 5460 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 3 ms 5460 KB Output is correct
10 Correct 3 ms 5460 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
12 Correct 3 ms 5588 KB Output is correct
13 Correct 4 ms 5560 KB Output is correct
14 Correct 3 ms 5560 KB Output is correct
15 Correct 4 ms 5588 KB Output is correct
16 Correct 3 ms 5560 KB Output is correct
17 Correct 3 ms 5588 KB Output is correct
18 Correct 3 ms 5556 KB Output is correct
19 Correct 6 ms 5820 KB Output is correct
20 Correct 6 ms 5844 KB Output is correct
21 Correct 5 ms 5844 KB Output is correct
22 Correct 6 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 3 ms 5460 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 3 ms 5460 KB Output is correct
6 Correct 3 ms 5460 KB Output is correct
7 Correct 3 ms 5460 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 3 ms 5460 KB Output is correct
10 Correct 3 ms 5460 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
12 Correct 3 ms 5588 KB Output is correct
13 Correct 4 ms 5560 KB Output is correct
14 Correct 3 ms 5560 KB Output is correct
15 Correct 4 ms 5588 KB Output is correct
16 Correct 3 ms 5560 KB Output is correct
17 Correct 3 ms 5588 KB Output is correct
18 Correct 3 ms 5556 KB Output is correct
19 Correct 6 ms 5820 KB Output is correct
20 Correct 6 ms 5844 KB Output is correct
21 Correct 5 ms 5844 KB Output is correct
22 Correct 6 ms 6100 KB Output is correct
23 Correct 12 ms 6060 KB Output is correct
24 Correct 12 ms 5952 KB Output is correct
25 Correct 12 ms 5980 KB Output is correct
26 Correct 12 ms 6052 KB Output is correct
27 Correct 12 ms 5972 KB Output is correct
28 Correct 396 ms 12256 KB Output is correct
29 Correct 92 ms 6988 KB Output is correct
30 Correct 987 ms 12780 KB Output is correct
31 Correct 1128 ms 14836 KB Output is correct
32 Correct 87 ms 6348 KB Output is correct
33 Correct 387 ms 8176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5716 KB Output is correct
2 Correct 4 ms 5716 KB Output is correct
3 Correct 4 ms 5716 KB Output is correct
4 Correct 4 ms 5692 KB Output is correct
5 Correct 4 ms 5688 KB Output is correct
6 Correct 5 ms 5844 KB Output is correct
7 Correct 5 ms 5844 KB Output is correct
8 Correct 7 ms 6080 KB Output is correct
9 Correct 6 ms 6100 KB Output is correct
10 Correct 6 ms 5972 KB Output is correct
11 Correct 7 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 3 ms 5460 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 3 ms 5460 KB Output is correct
6 Correct 3 ms 5460 KB Output is correct
7 Correct 3 ms 5460 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 3 ms 5460 KB Output is correct
10 Correct 3 ms 5460 KB Output is correct
11 Correct 3 ms 5460 KB Output is correct
12 Correct 3 ms 5588 KB Output is correct
13 Correct 4 ms 5560 KB Output is correct
14 Correct 3 ms 5560 KB Output is correct
15 Correct 4 ms 5588 KB Output is correct
16 Correct 3 ms 5560 KB Output is correct
17 Correct 3 ms 5588 KB Output is correct
18 Correct 3 ms 5556 KB Output is correct
19 Correct 6 ms 5820 KB Output is correct
20 Correct 6 ms 5844 KB Output is correct
21 Correct 5 ms 5844 KB Output is correct
22 Correct 6 ms 6100 KB Output is correct
23 Correct 12 ms 6060 KB Output is correct
24 Correct 12 ms 5952 KB Output is correct
25 Correct 12 ms 5980 KB Output is correct
26 Correct 12 ms 6052 KB Output is correct
27 Correct 12 ms 5972 KB Output is correct
28 Correct 396 ms 12256 KB Output is correct
29 Correct 92 ms 6988 KB Output is correct
30 Correct 987 ms 12780 KB Output is correct
31 Correct 1128 ms 14836 KB Output is correct
32 Correct 87 ms 6348 KB Output is correct
33 Correct 387 ms 8176 KB Output is correct
34 Correct 4 ms 5716 KB Output is correct
35 Correct 4 ms 5716 KB Output is correct
36 Correct 4 ms 5716 KB Output is correct
37 Correct 4 ms 5692 KB Output is correct
38 Correct 4 ms 5688 KB Output is correct
39 Correct 5 ms 5844 KB Output is correct
40 Correct 5 ms 5844 KB Output is correct
41 Correct 7 ms 6080 KB Output is correct
42 Correct 6 ms 6100 KB Output is correct
43 Correct 6 ms 5972 KB Output is correct
44 Correct 7 ms 6100 KB Output is correct
45 Correct 18 ms 6320 KB Output is correct
46 Correct 18 ms 6228 KB Output is correct
47 Correct 21 ms 6312 KB Output is correct
48 Incorrect 17 ms 6356 KB Output isn't correct
49 Halted 0 ms 0 KB -