답안 #134145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134145 2019-07-22T06:59:04 Z AngusRitossa 유괴 2 (JOI17_abduction2) C++14
27 / 100
339 ms 126840 KB
#include <bits/stdc++.h>
using namespace std;
int h, w, A[50010], B[50010], q;
int memo[2010][2010][4], done[2010][2010][4];
int dp(int a, int b, int c)
{
	if (a < 0 || b < 0 || a == h || b == w) return -1;
	if (done[a][b][c]) return memo[a][b][c];
	done[a][b][c] = 1;
	if (!c) // going up
	{
		if (B[b] < A[a]) return memo[a][b][c] = max(dp(a, b-1, 2), dp(a, b+1, 3))+1;
		else return memo[a][b][c] = dp(a-1, b, c)+1;
	}
	else if (c == 1)
	{
		if (B[b] < A[a]) return memo[a][b][c] = max(dp(a, b-1, 2), dp(a, b+1, 3))+1;
		else return memo[a][b][c] = dp(a+1, b, c)+1;
	}
	else if (c == 2)
	{
		if (B[b] > A[a]) return memo[a][b][c] = max(dp(a-1, b, 0), dp(a+1, b, 1))+1;
		else return memo[a][b][c] = dp(a, b-1, c)+1;
	}
	else
	{
		if (B[b] > A[a]) return memo[a][b][c] = max(dp(a-1, b, 0), dp(a+1, b, 1))+1;
		else return memo[a][b][c] = dp(a, b+1, c)+1;
	}
}
int main()
{
	scanf("%d%d%d", &h, &w, &q);
	for (int i = 0; i < h; i++) scanf("%d", &A[i]);
	for (int i = 0; i < w; i++) scanf("%d", &B[i]);
	for (int i = 0; i < q; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		int ans = max(dp(a-1, b, 0), max(dp(a+1, b, 1), max(dp(a, b-1, 2), dp(a, b+1, 3))))+1;
		printf("%d\n", ans);
	}
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &h, &w, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:34:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < h; i++) scanf("%d", &A[i]);
                              ~~~~~^~~~~~~~~~~~~
abduction2.cpp:35:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < w; i++) scanf("%d", &B[i]);
                              ~~~~~^~~~~~~~~~~~~
abduction2.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 21 ms 19064 KB Output is correct
13 Correct 11 ms 9464 KB Output is correct
14 Correct 25 ms 24568 KB Output is correct
15 Correct 24 ms 23544 KB Output is correct
16 Correct 13 ms 10872 KB Output is correct
17 Correct 23 ms 19832 KB Output is correct
18 Correct 57 ms 39800 KB Output is correct
19 Correct 186 ms 86620 KB Output is correct
20 Correct 235 ms 103728 KB Output is correct
21 Correct 205 ms 96120 KB Output is correct
22 Correct 324 ms 121428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 21 ms 19064 KB Output is correct
13 Correct 11 ms 9464 KB Output is correct
14 Correct 25 ms 24568 KB Output is correct
15 Correct 24 ms 23544 KB Output is correct
16 Correct 13 ms 10872 KB Output is correct
17 Correct 23 ms 19832 KB Output is correct
18 Correct 57 ms 39800 KB Output is correct
19 Correct 186 ms 86620 KB Output is correct
20 Correct 235 ms 103728 KB Output is correct
21 Correct 205 ms 96120 KB Output is correct
22 Correct 324 ms 121428 KB Output is correct
23 Runtime error 28 ms 2264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 109688 KB Output is correct
2 Correct 109 ms 110484 KB Output is correct
3 Correct 119 ms 120800 KB Output is correct
4 Correct 114 ms 114000 KB Output is correct
5 Correct 120 ms 120656 KB Output is correct
6 Correct 174 ms 105336 KB Output is correct
7 Correct 171 ms 103352 KB Output is correct
8 Correct 268 ms 117180 KB Output is correct
9 Correct 257 ms 114268 KB Output is correct
10 Correct 259 ms 115704 KB Output is correct
11 Correct 339 ms 126840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 21 ms 19064 KB Output is correct
13 Correct 11 ms 9464 KB Output is correct
14 Correct 25 ms 24568 KB Output is correct
15 Correct 24 ms 23544 KB Output is correct
16 Correct 13 ms 10872 KB Output is correct
17 Correct 23 ms 19832 KB Output is correct
18 Correct 57 ms 39800 KB Output is correct
19 Correct 186 ms 86620 KB Output is correct
20 Correct 235 ms 103728 KB Output is correct
21 Correct 205 ms 96120 KB Output is correct
22 Correct 324 ms 121428 KB Output is correct
23 Runtime error 28 ms 2264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -