Submission #25703

# Submission time Handle Problem Language Result Execution time Memory
25703 2017-06-23T17:32:38 Z gs14004 Abduction 2 (JOI17_abduction2) C++11
44 / 100
5000 ms 10684 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

struct line{
	int pos, val, axis;
	bool operator<(const line &l)const{
		return val < l.val;
	}
}a[100005];

int n, m, q;
int st[100005], ed[100005];
lint ldp[100005], rdp[100005];
int rev[2][50005];

lint solve(int x, int y, int cs){
	memset(ldp, 0, sizeof(ldp));
	memset(rdp, 0, sizeof(rdp));
	map<pi, lint> dp;
	set<int> s[2];
	lint ret = 0;
	for(int i=0; i<n+m; i++){
		set<int> ::iterator l, r;
		if(a[i].axis == 0){
			if(cs & 2){
				l = r = s[1].lower_bound(y);
			}
			else{
				l = r = s[1].upper_bound(y);
			}
			if(r != s[1].end()) ed[i] = *r;
			else ed[i] = m-1;
			if(l != s[1].begin()) st[i] = *--l;
			else st[i] = 0;
			if(rev[1][ed[i]] < i){
				int r = rev[1][ed[i]];
				rdp[i] = max(ldp[r] + abs(st[r] - a[i].pos), rdp[r] + abs(ed[r] - a[i].pos));
			}
			if(rev[1][st[i]] < i){
				int r = rev[1][st[i]];
				ldp[i] = max(ldp[r] + abs(st[r] - a[i].pos), rdp[r] + abs(ed[r] - a[i].pos));
			}
		}
		else{
			if(cs & 1){
				l = r = s[0].lower_bound(x);
			}
			else{
				l = r = s[0].upper_bound(x);
			}
			if(r != s[0].end()) ed[i] = *r;
			else ed[i] = n-1;
			if(l != s[0].begin()) st[i] = *--l;
			else st[i] = 0;
			if(rev[0][ed[i]] < i){
				int r = rev[0][ed[i]];
				rdp[i] = max(ldp[r] + abs(st[r] - a[i].pos), rdp[r] + abs(ed[r] - a[i].pos));
			}
			if(rev[0][st[i]] < i){
				int r = rev[0][st[i]];
				ldp[i] = max(ldp[r] + abs(st[r] - a[i].pos), rdp[r] + abs(ed[r] - a[i].pos));
			}
		}
		if(a[i].axis == 0 && a[i].pos == x){
			ret = max({ret, ldp[i] + abs(st[i] - y), rdp[i] + abs(ed[i] - y)});
		}
		if(a[i].axis == 1 && a[i].pos == y){
			ret = max({ret, ldp[i] + abs(st[i] - x), rdp[i] + abs(ed[i] - x)});
		}
		s[a[i].axis].insert(a[i].pos);
	}
	return ret;
}

int main(){
	scanf("%d %d %d",&n,&m,&q);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i].val);
		a[i].pos = i;
		a[i].axis = 0;
	}
	for(int i=0; i<m; i++){
		scanf("%d",&a[i+n].val);
		a[i+n].pos = i;
		a[i+n].axis = 1;
	}
	sort(a, a+n+m);
	reverse(a, a+n+m);
	for(int i=0; i<n+m; i++){
		rev[a[i].axis][a[i].pos] = i;
	}
	for(int i=0; i<q; i++){
		int x, y;
		scanf("%d %d",&x,&y);
		lint ret = 0;
		for(int j=0; j<4; j++) ret = max(ret, solve(x-1, y-1, j));
		printf("%lld\n", ret);
	}
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:79:28: 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:81:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i].val);
                        ^
abduction2.cpp:86:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i+n].val);
                          ^
abduction2.cpp:97:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5932 KB Output is correct
2 Correct 0 ms 5932 KB Output is correct
3 Correct 0 ms 5932 KB Output is correct
4 Correct 0 ms 5932 KB Output is correct
5 Correct 0 ms 5932 KB Output is correct
6 Correct 0 ms 5932 KB Output is correct
7 Correct 0 ms 5932 KB Output is correct
8 Correct 0 ms 5932 KB Output is correct
9 Correct 0 ms 5932 KB Output is correct
10 Correct 0 ms 5932 KB Output is correct
11 Correct 0 ms 5932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5932 KB Output is correct
2 Correct 0 ms 5932 KB Output is correct
3 Correct 0 ms 5932 KB Output is correct
4 Correct 0 ms 5932 KB Output is correct
5 Correct 0 ms 5932 KB Output is correct
6 Correct 0 ms 5932 KB Output is correct
7 Correct 0 ms 5932 KB Output is correct
8 Correct 0 ms 5932 KB Output is correct
9 Correct 0 ms 5932 KB Output is correct
10 Correct 0 ms 5932 KB Output is correct
11 Correct 0 ms 5932 KB Output is correct
12 Correct 6 ms 6196 KB Output is correct
13 Correct 6 ms 6196 KB Output is correct
14 Correct 3 ms 6196 KB Output is correct
15 Correct 3 ms 6196 KB Output is correct
16 Correct 6 ms 6196 KB Output is correct
17 Correct 6 ms 6196 KB Output is correct
18 Correct 0 ms 6196 KB Output is correct
19 Correct 3 ms 6196 KB Output is correct
20 Correct 6 ms 6064 KB Output is correct
21 Correct 3 ms 6064 KB Output is correct
22 Correct 6 ms 6196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5932 KB Output is correct
2 Correct 0 ms 5932 KB Output is correct
3 Correct 0 ms 5932 KB Output is correct
4 Correct 0 ms 5932 KB Output is correct
5 Correct 0 ms 5932 KB Output is correct
6 Correct 0 ms 5932 KB Output is correct
7 Correct 0 ms 5932 KB Output is correct
8 Correct 0 ms 5932 KB Output is correct
9 Correct 0 ms 5932 KB Output is correct
10 Correct 0 ms 5932 KB Output is correct
11 Correct 0 ms 5932 KB Output is correct
12 Correct 6 ms 6196 KB Output is correct
13 Correct 6 ms 6196 KB Output is correct
14 Correct 3 ms 6196 KB Output is correct
15 Correct 3 ms 6196 KB Output is correct
16 Correct 6 ms 6196 KB Output is correct
17 Correct 6 ms 6196 KB Output is correct
18 Correct 0 ms 6196 KB Output is correct
19 Correct 3 ms 6196 KB Output is correct
20 Correct 6 ms 6064 KB Output is correct
21 Correct 3 ms 6064 KB Output is correct
22 Correct 6 ms 6196 KB Output is correct
23 Correct 296 ms 10684 KB Output is correct
24 Correct 363 ms 10684 KB Output is correct
25 Correct 349 ms 10684 KB Output is correct
26 Correct 319 ms 10684 KB Output is correct
27 Correct 313 ms 10684 KB Output is correct
28 Correct 153 ms 10684 KB Output is correct
29 Correct 153 ms 10684 KB Output is correct
30 Correct 193 ms 10684 KB Output is correct
31 Correct 213 ms 10684 KB Output is correct
32 Correct 199 ms 10552 KB Output is correct
33 Correct 246 ms 10684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 389 ms 6196 KB Output is correct
2 Correct 406 ms 6196 KB Output is correct
3 Correct 423 ms 6196 KB Output is correct
4 Correct 436 ms 6196 KB Output is correct
5 Correct 413 ms 6196 KB Output is correct
6 Correct 229 ms 6196 KB Output is correct
7 Correct 243 ms 6196 KB Output is correct
8 Correct 359 ms 6196 KB Output is correct
9 Correct 366 ms 6196 KB Output is correct
10 Correct 373 ms 6196 KB Output is correct
11 Correct 399 ms 6196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5932 KB Output is correct
2 Correct 0 ms 5932 KB Output is correct
3 Correct 0 ms 5932 KB Output is correct
4 Correct 0 ms 5932 KB Output is correct
5 Correct 0 ms 5932 KB Output is correct
6 Correct 0 ms 5932 KB Output is correct
7 Correct 0 ms 5932 KB Output is correct
8 Correct 0 ms 5932 KB Output is correct
9 Correct 0 ms 5932 KB Output is correct
10 Correct 0 ms 5932 KB Output is correct
11 Correct 0 ms 5932 KB Output is correct
12 Correct 6 ms 6196 KB Output is correct
13 Correct 6 ms 6196 KB Output is correct
14 Correct 3 ms 6196 KB Output is correct
15 Correct 3 ms 6196 KB Output is correct
16 Correct 6 ms 6196 KB Output is correct
17 Correct 6 ms 6196 KB Output is correct
18 Correct 0 ms 6196 KB Output is correct
19 Correct 3 ms 6196 KB Output is correct
20 Correct 6 ms 6064 KB Output is correct
21 Correct 3 ms 6064 KB Output is correct
22 Correct 6 ms 6196 KB Output is correct
23 Correct 296 ms 10684 KB Output is correct
24 Correct 363 ms 10684 KB Output is correct
25 Correct 349 ms 10684 KB Output is correct
26 Correct 319 ms 10684 KB Output is correct
27 Correct 313 ms 10684 KB Output is correct
28 Correct 153 ms 10684 KB Output is correct
29 Correct 153 ms 10684 KB Output is correct
30 Correct 193 ms 10684 KB Output is correct
31 Correct 213 ms 10684 KB Output is correct
32 Correct 199 ms 10552 KB Output is correct
33 Correct 246 ms 10684 KB Output is correct
34 Correct 389 ms 6196 KB Output is correct
35 Correct 406 ms 6196 KB Output is correct
36 Correct 423 ms 6196 KB Output is correct
37 Correct 436 ms 6196 KB Output is correct
38 Correct 413 ms 6196 KB Output is correct
39 Correct 229 ms 6196 KB Output is correct
40 Correct 243 ms 6196 KB Output is correct
41 Correct 359 ms 6196 KB Output is correct
42 Correct 366 ms 6196 KB Output is correct
43 Correct 373 ms 6196 KB Output is correct
44 Correct 399 ms 6196 KB Output is correct
45 Execution timed out 5000 ms 10684 KB Execution timed out
46 Halted 0 ms 0 KB -