Submission #26217

# Submission time Handle Problem Language Result Execution time Memory
26217 2017-06-28T11:39:57 Z imsifile Abduction 2 (JOI17_abduction2) C++14
44 / 100
4703 ms 16712 KB
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;

typedef long long lld;

int H, W, Q;
int ho[150505], ver[150505];
map<pair<int,int>, lld> vd, hd;

lld verti(int, int);
lld hori(int, int);

lld verti(int h, int v){
	int gap = vd[make_pair(h,v)];
	if(gap) return gap;
	int val = ver[v];
	int i;
	lld up=0, down=0;
	for(i=h+1; i<H; i++){
		up=i-h;
		if(ho[i]>val)break;
	}
	if(i<H) up += hori(v, i);
	for(i=h-1; i>=0; i--){
		down=h-i;
		if(ho[i]>val)break;
	}
	if(i>=0) down += hori(v, i);
	return vd[make_pair(h,v)] = max(up, down);
}

lld hori(int v, int h){
	int gap = hd[make_pair(h,v)];
	if(gap) return gap;
	int val = ho[h];
	int i;
	lld up=0, down=0;
	for(i=v+1; i<W; i++){
		up=i-v;
		if(ver[i]>val)break;
	}
	if(i<W) up += verti(h, i);
	for(i=v-1; i>=0; i--){
		down=v-i;
		if(ver[i]>val)break;
	}
	if(i>=0) down += verti(h, i);
	return hd[make_pair(h,v)]=max(up, down);
}

int main(){
	scanf("%d%d%d", &H, &W, &Q);
	for(int i=0; i<H; i++) scanf("%d", &ho[i]);
	for(int i=0; i<W; i++) scanf("%d", &ver[i]);
	while(Q--){
		int h, v;
		scanf("%d%d", &h, &v), h--, v--;
		printf("%lld\n", max(verti(h, v), hori(v, h)));
	}
	return 0;
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:54:29: 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:55:44: 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", &ho[i]);
                                            ^
abduction2.cpp:56:45: 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", &ver[i]);
                                             ^
abduction2.cpp:59:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &h, &v), h--, v--;
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2352 KB Output is correct
2 Correct 0 ms 2352 KB Output is correct
3 Correct 0 ms 2352 KB Output is correct
4 Correct 0 ms 2352 KB Output is correct
5 Correct 0 ms 2352 KB Output is correct
6 Correct 0 ms 2352 KB Output is correct
7 Correct 0 ms 2352 KB Output is correct
8 Correct 0 ms 2352 KB Output is correct
9 Correct 0 ms 2352 KB Output is correct
10 Correct 0 ms 2352 KB Output is correct
11 Correct 0 ms 2352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2352 KB Output is correct
2 Correct 0 ms 2352 KB Output is correct
3 Correct 0 ms 2352 KB Output is correct
4 Correct 0 ms 2352 KB Output is correct
5 Correct 0 ms 2352 KB Output is correct
6 Correct 0 ms 2352 KB Output is correct
7 Correct 0 ms 2352 KB Output is correct
8 Correct 0 ms 2352 KB Output is correct
9 Correct 0 ms 2352 KB Output is correct
10 Correct 0 ms 2352 KB Output is correct
11 Correct 0 ms 2352 KB Output is correct
12 Correct 0 ms 2352 KB Output is correct
13 Correct 0 ms 2352 KB Output is correct
14 Correct 0 ms 2352 KB Output is correct
15 Correct 0 ms 2352 KB Output is correct
16 Correct 0 ms 2352 KB Output is correct
17 Correct 0 ms 2352 KB Output is correct
18 Correct 0 ms 2352 KB Output is correct
19 Correct 6 ms 2484 KB Output is correct
20 Correct 6 ms 2616 KB Output is correct
21 Correct 3 ms 2616 KB Output is correct
22 Correct 9 ms 2752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2352 KB Output is correct
2 Correct 0 ms 2352 KB Output is correct
3 Correct 0 ms 2352 KB Output is correct
4 Correct 0 ms 2352 KB Output is correct
5 Correct 0 ms 2352 KB Output is correct
6 Correct 0 ms 2352 KB Output is correct
7 Correct 0 ms 2352 KB Output is correct
8 Correct 0 ms 2352 KB Output is correct
9 Correct 0 ms 2352 KB Output is correct
10 Correct 0 ms 2352 KB Output is correct
11 Correct 0 ms 2352 KB Output is correct
12 Correct 0 ms 2352 KB Output is correct
13 Correct 0 ms 2352 KB Output is correct
14 Correct 0 ms 2352 KB Output is correct
15 Correct 0 ms 2352 KB Output is correct
16 Correct 0 ms 2352 KB Output is correct
17 Correct 0 ms 2352 KB Output is correct
18 Correct 0 ms 2352 KB Output is correct
19 Correct 6 ms 2484 KB Output is correct
20 Correct 6 ms 2616 KB Output is correct
21 Correct 3 ms 2616 KB Output is correct
22 Correct 9 ms 2752 KB Output is correct
23 Correct 13 ms 2352 KB Output is correct
24 Correct 16 ms 2352 KB Output is correct
25 Correct 23 ms 2352 KB Output is correct
26 Correct 23 ms 2352 KB Output is correct
27 Correct 16 ms 2352 KB Output is correct
28 Correct 1016 ms 7404 KB Output is correct
29 Correct 236 ms 2928 KB Output is correct
30 Correct 2799 ms 8472 KB Output is correct
31 Correct 3159 ms 10352 KB Output is correct
32 Correct 203 ms 2616 KB Output is correct
33 Correct 996 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2484 KB Output is correct
2 Correct 0 ms 2484 KB Output is correct
3 Correct 3 ms 2484 KB Output is correct
4 Correct 0 ms 2484 KB Output is correct
5 Correct 0 ms 2484 KB Output is correct
6 Correct 3 ms 2484 KB Output is correct
7 Correct 3 ms 2484 KB Output is correct
8 Correct 9 ms 2748 KB Output is correct
9 Correct 9 ms 2748 KB Output is correct
10 Correct 9 ms 2748 KB Output is correct
11 Correct 9 ms 2880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2352 KB Output is correct
2 Correct 0 ms 2352 KB Output is correct
3 Correct 0 ms 2352 KB Output is correct
4 Correct 0 ms 2352 KB Output is correct
5 Correct 0 ms 2352 KB Output is correct
6 Correct 0 ms 2352 KB Output is correct
7 Correct 0 ms 2352 KB Output is correct
8 Correct 0 ms 2352 KB Output is correct
9 Correct 0 ms 2352 KB Output is correct
10 Correct 0 ms 2352 KB Output is correct
11 Correct 0 ms 2352 KB Output is correct
12 Correct 0 ms 2352 KB Output is correct
13 Correct 0 ms 2352 KB Output is correct
14 Correct 0 ms 2352 KB Output is correct
15 Correct 0 ms 2352 KB Output is correct
16 Correct 0 ms 2352 KB Output is correct
17 Correct 0 ms 2352 KB Output is correct
18 Correct 0 ms 2352 KB Output is correct
19 Correct 6 ms 2484 KB Output is correct
20 Correct 6 ms 2616 KB Output is correct
21 Correct 3 ms 2616 KB Output is correct
22 Correct 9 ms 2752 KB Output is correct
23 Correct 13 ms 2352 KB Output is correct
24 Correct 16 ms 2352 KB Output is correct
25 Correct 23 ms 2352 KB Output is correct
26 Correct 23 ms 2352 KB Output is correct
27 Correct 16 ms 2352 KB Output is correct
28 Correct 1016 ms 7404 KB Output is correct
29 Correct 236 ms 2928 KB Output is correct
30 Correct 2799 ms 8472 KB Output is correct
31 Correct 3159 ms 10352 KB Output is correct
32 Correct 203 ms 2616 KB Output is correct
33 Correct 996 ms 4216 KB Output is correct
34 Correct 0 ms 2484 KB Output is correct
35 Correct 0 ms 2484 KB Output is correct
36 Correct 3 ms 2484 KB Output is correct
37 Correct 0 ms 2484 KB Output is correct
38 Correct 0 ms 2484 KB Output is correct
39 Correct 3 ms 2484 KB Output is correct
40 Correct 3 ms 2484 KB Output is correct
41 Correct 9 ms 2748 KB Output is correct
42 Correct 9 ms 2748 KB Output is correct
43 Correct 9 ms 2748 KB Output is correct
44 Correct 9 ms 2880 KB Output is correct
45 Correct 29 ms 2616 KB Output is correct
46 Correct 26 ms 2616 KB Output is correct
47 Correct 29 ms 2616 KB Output is correct
48 Correct 29 ms 2616 KB Output is correct
49 Correct 29 ms 2616 KB Output is correct
50 Correct 1189 ms 6780 KB Output is correct
51 Correct 1223 ms 7444 KB Output is correct
52 Correct 3536 ms 12476 KB Output is correct
53 Correct 3379 ms 12144 KB Output is correct
54 Correct 3516 ms 11644 KB Output is correct
55 Incorrect 4703 ms 16712 KB Output isn't correct
56 Halted 0 ms 0 KB -