Submission #204503

# Submission time Handle Problem Language Result Execution time Memory
204503 2020-02-26T07:02:59 Z arnold518 Abduction 2 (JOI17_abduction2) C++14
44 / 100
208 ms 31864 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 5e4;

int N, M, Q;
int A[MAXN+10], B[MAXN+10];

int LA[MAXN+10][20], RA[MAXN+10][20];
int LB[MAXN+10][20], RB[MAXN+10][20];

map<pair<pii, int>, int> memo;

int solve(int y, int x, int d)
{
	if(memo.find({{y, x}, d})!=memo.end()) return memo[{{y, x}, d}];
	int i, j;

	int ret=0;
	int l, r, k;
	if(d==0)
	{
		l=y-1; r=y+1; k=B[x];
		for(i=16; i>=0; i--) if(LA[l][i]<=k) l=max(0, l-(1<<i));
		for(i=16; i>=0; i--) if(RA[r][i]<=k) r=min(N+1, r+(1<<i));

		if(l==0) ret=max(ret, y-1);
		else ret=max(ret, y-l+solve(l, x, 1));

		if(r==N+1) ret=max(ret, N-y);
		else ret=max(ret, r-y+solve(r, x, 1));
	}
	else
	{
		l=x-1; r=x+1; k=A[y];
		for(i=16; i>=0; i--) if(LB[l][i]<=k) l=max(0, l-(1<<i));
		for(i=16; i>=0; i--) if(RB[r][i]<=k) r=min(M+1, r+(1<<i));

		if(l==0) ret=max(ret, x-1);
		else ret=max(ret, x-l+solve(y, l, 0));

		if(r==M+1) ret=max(ret, M-x);
		else ret=max(ret, r-x+solve(y, r, 0));	
	}
	memo[{{y, x}, d}]=ret;
	return ret;
}

int main()
{
	int i, j;

	scanf("%d%d%d", &N, &M, &Q);
	for(i=1; i<=N; i++) scanf("%d", &A[i]);
	for(i=1; i<=M; i++) scanf("%d", &B[i]);

	for(i=1; i<=N; i++) LA[i][0]=RA[i][0]=A[i];
	for(i=1; i<=16; i++) for(j=1; j<=N; j++) LA[j][i]=max(LA[j][i-1], LA[max(0, j-(1<<(i-1)))][i-1]);
	for(i=1; i<=16; i++) for(j=1; j<=N; j++) RA[j][i]=max(RA[j][i-1], RA[min(N+1, j+(1<<(i-1)))][i-1]);

	for(i=1; i<=M; i++) LB[i][0]=RB[i][0]=B[i];
	for(i=1; i<=16; i++) for(j=1; j<=M; j++) LB[j][i]=max(LB[j][i-1], LB[max(0, j-(1<<(i-1)))][i-1]);
	for(i=1; i<=16; i++) for(j=1; j<=M; j++) RB[j][i]=max(RB[j][i-1], RB[min(M+1, j+(1<<(i-1)))][i-1]);	

	while(Q--)
	{
		int y, x;
		scanf("%d%d", &y, &x);
		printf("%d\n", max(solve(y, x, 0), solve(y, x, 1)));
	}
}

Compilation message

abduction2.cpp: In function 'int solve(int, int, int)':
abduction2.cpp:21:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
abduction2.cpp: In function 'int main()':
abduction2.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:58:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N; i++) scanf("%d", &A[i]);
                      ~~~~~^~~~~~~~~~~~~
abduction2.cpp:59:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=M; i++) scanf("%d", &B[i]);
                      ~~~~~^~~~~~~~~~~~~
abduction2.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &y, &x);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 1016 KB Output is correct
13 Correct 6 ms 1016 KB Output is correct
14 Correct 6 ms 1016 KB Output is correct
15 Correct 6 ms 1016 KB Output is correct
16 Correct 6 ms 1016 KB Output is correct
17 Correct 6 ms 1016 KB Output is correct
18 Correct 6 ms 1016 KB Output is correct
19 Correct 8 ms 1196 KB Output is correct
20 Correct 8 ms 1272 KB Output is correct
21 Correct 8 ms 1272 KB Output is correct
22 Correct 9 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 1016 KB Output is correct
13 Correct 6 ms 1016 KB Output is correct
14 Correct 6 ms 1016 KB Output is correct
15 Correct 6 ms 1016 KB Output is correct
16 Correct 6 ms 1016 KB Output is correct
17 Correct 6 ms 1016 KB Output is correct
18 Correct 6 ms 1016 KB Output is correct
19 Correct 8 ms 1196 KB Output is correct
20 Correct 8 ms 1272 KB Output is correct
21 Correct 8 ms 1272 KB Output is correct
22 Correct 9 ms 1528 KB Output is correct
23 Correct 47 ms 17400 KB Output is correct
24 Correct 42 ms 17400 KB Output is correct
25 Correct 44 ms 17272 KB Output is correct
26 Correct 43 ms 17272 KB Output is correct
27 Correct 46 ms 17400 KB Output is correct
28 Correct 54 ms 22392 KB Output is correct
29 Correct 43 ms 18044 KB Output is correct
30 Correct 97 ms 23692 KB Output is correct
31 Correct 114 ms 25344 KB Output is correct
32 Correct 43 ms 17468 KB Output is correct
33 Correct 55 ms 19320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1144 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
3 Correct 9 ms 1148 KB Output is correct
4 Correct 8 ms 1144 KB Output is correct
5 Correct 8 ms 1144 KB Output is correct
6 Correct 8 ms 1276 KB Output is correct
7 Correct 7 ms 1272 KB Output is correct
8 Correct 10 ms 1528 KB Output is correct
9 Correct 11 ms 1528 KB Output is correct
10 Correct 10 ms 1404 KB Output is correct
11 Correct 11 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 1016 KB Output is correct
13 Correct 6 ms 1016 KB Output is correct
14 Correct 6 ms 1016 KB Output is correct
15 Correct 6 ms 1016 KB Output is correct
16 Correct 6 ms 1016 KB Output is correct
17 Correct 6 ms 1016 KB Output is correct
18 Correct 6 ms 1016 KB Output is correct
19 Correct 8 ms 1196 KB Output is correct
20 Correct 8 ms 1272 KB Output is correct
21 Correct 8 ms 1272 KB Output is correct
22 Correct 9 ms 1528 KB Output is correct
23 Correct 47 ms 17400 KB Output is correct
24 Correct 42 ms 17400 KB Output is correct
25 Correct 44 ms 17272 KB Output is correct
26 Correct 43 ms 17272 KB Output is correct
27 Correct 46 ms 17400 KB Output is correct
28 Correct 54 ms 22392 KB Output is correct
29 Correct 43 ms 18044 KB Output is correct
30 Correct 97 ms 23692 KB Output is correct
31 Correct 114 ms 25344 KB Output is correct
32 Correct 43 ms 17468 KB Output is correct
33 Correct 55 ms 19320 KB Output is correct
34 Correct 8 ms 1144 KB Output is correct
35 Correct 8 ms 1144 KB Output is correct
36 Correct 9 ms 1148 KB Output is correct
37 Correct 8 ms 1144 KB Output is correct
38 Correct 8 ms 1144 KB Output is correct
39 Correct 8 ms 1276 KB Output is correct
40 Correct 7 ms 1272 KB Output is correct
41 Correct 10 ms 1528 KB Output is correct
42 Correct 11 ms 1528 KB Output is correct
43 Correct 10 ms 1404 KB Output is correct
44 Correct 11 ms 1528 KB Output is correct
45 Correct 49 ms 17632 KB Output is correct
46 Correct 48 ms 17656 KB Output is correct
47 Correct 46 ms 17660 KB Output is correct
48 Correct 46 ms 17656 KB Output is correct
49 Correct 46 ms 17656 KB Output is correct
50 Correct 58 ms 21880 KB Output is correct
51 Correct 58 ms 22520 KB Output is correct
52 Correct 141 ms 27640 KB Output is correct
53 Correct 142 ms 26972 KB Output is correct
54 Correct 132 ms 26616 KB Output is correct
55 Incorrect 208 ms 31864 KB Output isn't correct
56 Halted 0 ms 0 KB -