답안 #21013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21013 2017-03-29T09:41:49 Z model_code 유괴 2 (JOI17_abduction2) C++11
100 / 100
3266 ms 286808 KB
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
int p[110000];
int q[110000];
int A[110000];
int B[110000];

int v1[110000][20];
int w1[110000][20];
int v2[110000][20];
int w2[110000][20];
int N,M;
map<pair<pair<int,int>,int>,long long> dp;
long long dfs(int a,int b,int c){
	//printf("%d %d %d\n",a,b,c);
	if(dp.count(make_pair(make_pair(a,b),c)))return dp[make_pair(make_pair(a,b),c)];
	pair<pair<int,int>,int> pos=make_pair(make_pair(a,b),c);
	int num;
	if(c<2)num=p[a];
	else num=q[b];
	if(c==0){
		int at=b+1;
		for(int i=19;i>=0;i--){
			if(at>101000)break;
			if(w1[at][i]<num){
				at+=(1<<i);
			}
		}
		if(at>=M){
			return dp[pos]=M-1-b;
		}else{
			return dp[pos]=max(dfs(a,at,2),dfs(a,at,3))+at-b;
		}
	}else if(c==1){
		int at=b-1;
		at=M-1-at;
		for(int i=19;i>=0;i--){
			if(at>101000)break;
			if(w2[at][i]<num){
				at+=(1<<i);
			}
		}
		if(at>=M){
			return dp[pos]=b;
		}else{
			at=M-1-at;
			return dp[pos]=max(dfs(a,at,2),dfs(a,at,3))+b-at;
		}
	}else if(c==2){
		int at=a+1;
		for(int i=19;i>=0;i--){
			if(at>101000)break;
			if(v1[at][i]<num){
				at+=(1<<i);
			}
		}
		if(at>=N){
			return dp[pos]=N-1-a;
		}else{
			return dp[pos]=max(dfs(at,b,0),dfs(at,b,1))+at-a;
		}
	}else{
		int at=a-1;
		at=N-1-at;
		for(int i=19;i>=0;i--){
			if(at>101000)break;
			if(v2[at][i]<num){
				at+=(1<<i);
			}
		}
		if(at>=N){
			return dp[pos]=a;
		}else{
			at=N-1-at;
			return dp[pos]=max(dfs(at,b,0),dfs(at,b,1))+a-at;
		}
	}
//	return dp[make_pair(make_pair(a,b),c)]=ret;
}
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	N=a;M=b;
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<b;i++)scanf("%d",q+i);
	for(int i=0;i<c;i++){
		scanf("%d%d",A+i,B+i);
		A[i]--;B[i]--;
	}
	for(int i=0;i<a;i++){
		v1[i][0]=p[i];
	}
	for(int i=0;i<b;i++){
		w1[i][0]=q[i];
	}
	for(int i=1;i<20;i++){
		for(int j=0;j<a;j++){
			v1[j][i]=max(v1[j][i-1],v1[min(101000,j+(1<<(i-1)))][i-1]);
		}
		for(int j=0;j<b;j++){
			w1[j][i]=max(w1[j][i-1],w1[min(101000,j+(1<<(i-1)))][i-1]);
		}
	}

	for(int i=0;i<a;i++){
		v2[i][0]=p[a-1-i];
	}
	for(int i=0;i<b;i++){
		w2[i][0]=q[b-1-i];
	}
	for(int i=1;i<20;i++){
		for(int j=0;j<a;j++){
			v2[j][i]=max(v2[j][i-1],v2[min(101000,j+(1<<(i-1)))][i-1]);
		}
		for(int j=0;j<b;j++){
			w2[j][i]=max(w2[j][i-1],w2[min(101000,j+(1<<(i-1)))][i-1]);
		}
	}
	for(int i=0;i<c;i++){
		long long ret=0;
		for(int j=0;j<4;j++){
		//	printf("%d %d %d: %lld\n",A[i],B[i],j,dfs(A[i],B[i],j));
			ret=max(ret,dfs(A[i],B[i],j));
		}
		printf("%lld\n",ret);
	}
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:94:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int a,b,c;scanf("%d%d%d",&a,&b,&c);
                                    ^
abduction2.cpp:96:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<a;i++)scanf("%d",p+i);
                                     ^
abduction2.cpp:97:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<b;i++)scanf("%d",q+i);
                                     ^
abduction2.cpp:99:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",A+i,B+i);
                        ^

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 37272 KB Output is correct
2 Correct 0 ms 37272 KB Output is correct
3 Correct 0 ms 37272 KB Output is correct
4 Correct 0 ms 37272 KB Output is correct
5 Correct 0 ms 37272 KB Output is correct
6 Correct 0 ms 37272 KB Output is correct
7 Correct 0 ms 37272 KB Output is correct
8 Correct 0 ms 37272 KB Output is correct
9 Correct 0 ms 37272 KB Output is correct
10 Correct 0 ms 37272 KB Output is correct
11 Correct 0 ms 37272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 37272 KB Output is correct
2 Correct 0 ms 37272 KB Output is correct
3 Correct 0 ms 37272 KB Output is correct
4 Correct 0 ms 37272 KB Output is correct
5 Correct 0 ms 37272 KB Output is correct
6 Correct 0 ms 37272 KB Output is correct
7 Correct 0 ms 37272 KB Output is correct
8 Correct 0 ms 37272 KB Output is correct
9 Correct 0 ms 37272 KB Output is correct
10 Correct 0 ms 37272 KB Output is correct
11 Correct 0 ms 37272 KB Output is correct
12 Correct 0 ms 37272 KB Output is correct
13 Correct 0 ms 37272 KB Output is correct
14 Correct 0 ms 37272 KB Output is correct
15 Correct 0 ms 37272 KB Output is correct
16 Correct 0 ms 37272 KB Output is correct
17 Correct 0 ms 37272 KB Output is correct
18 Correct 0 ms 37272 KB Output is correct
19 Correct 0 ms 37668 KB Output is correct
20 Correct 3 ms 37800 KB Output is correct
21 Correct 3 ms 37668 KB Output is correct
22 Correct 6 ms 38064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 37272 KB Output is correct
2 Correct 0 ms 37272 KB Output is correct
3 Correct 0 ms 37272 KB Output is correct
4 Correct 0 ms 37272 KB Output is correct
5 Correct 0 ms 37272 KB Output is correct
6 Correct 0 ms 37272 KB Output is correct
7 Correct 0 ms 37272 KB Output is correct
8 Correct 0 ms 37272 KB Output is correct
9 Correct 0 ms 37272 KB Output is correct
10 Correct 0 ms 37272 KB Output is correct
11 Correct 0 ms 37272 KB Output is correct
12 Correct 0 ms 37272 KB Output is correct
13 Correct 0 ms 37272 KB Output is correct
14 Correct 0 ms 37272 KB Output is correct
15 Correct 0 ms 37272 KB Output is correct
16 Correct 0 ms 37272 KB Output is correct
17 Correct 0 ms 37272 KB Output is correct
18 Correct 0 ms 37272 KB Output is correct
19 Correct 0 ms 37668 KB Output is correct
20 Correct 3 ms 37800 KB Output is correct
21 Correct 3 ms 37668 KB Output is correct
22 Correct 6 ms 38064 KB Output is correct
23 Correct 43 ms 37272 KB Output is correct
24 Correct 39 ms 37272 KB Output is correct
25 Correct 43 ms 37272 KB Output is correct
26 Correct 43 ms 37272 KB Output is correct
27 Correct 43 ms 37272 KB Output is correct
28 Correct 76 ms 43284 KB Output is correct
29 Correct 43 ms 38104 KB Output is correct
30 Correct 176 ms 47644 KB Output is correct
31 Correct 233 ms 50700 KB Output is correct
32 Correct 49 ms 37800 KB Output is correct
33 Correct 69 ms 40408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 37668 KB Output is correct
2 Correct 3 ms 37668 KB Output is correct
3 Correct 3 ms 37668 KB Output is correct
4 Correct 6 ms 37668 KB Output is correct
5 Correct 3 ms 37668 KB Output is correct
6 Correct 3 ms 37536 KB Output is correct
7 Correct 3 ms 37536 KB Output is correct
8 Correct 6 ms 38064 KB Output is correct
9 Correct 6 ms 38064 KB Output is correct
10 Correct 9 ms 38064 KB Output is correct
11 Correct 13 ms 38328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 37272 KB Output is correct
2 Correct 0 ms 37272 KB Output is correct
3 Correct 0 ms 37272 KB Output is correct
4 Correct 0 ms 37272 KB Output is correct
5 Correct 0 ms 37272 KB Output is correct
6 Correct 0 ms 37272 KB Output is correct
7 Correct 0 ms 37272 KB Output is correct
8 Correct 0 ms 37272 KB Output is correct
9 Correct 0 ms 37272 KB Output is correct
10 Correct 0 ms 37272 KB Output is correct
11 Correct 0 ms 37272 KB Output is correct
12 Correct 0 ms 37272 KB Output is correct
13 Correct 0 ms 37272 KB Output is correct
14 Correct 0 ms 37272 KB Output is correct
15 Correct 0 ms 37272 KB Output is correct
16 Correct 0 ms 37272 KB Output is correct
17 Correct 0 ms 37272 KB Output is correct
18 Correct 0 ms 37272 KB Output is correct
19 Correct 0 ms 37668 KB Output is correct
20 Correct 3 ms 37800 KB Output is correct
21 Correct 3 ms 37668 KB Output is correct
22 Correct 6 ms 38064 KB Output is correct
23 Correct 43 ms 37272 KB Output is correct
24 Correct 39 ms 37272 KB Output is correct
25 Correct 43 ms 37272 KB Output is correct
26 Correct 43 ms 37272 KB Output is correct
27 Correct 43 ms 37272 KB Output is correct
28 Correct 76 ms 43284 KB Output is correct
29 Correct 43 ms 38104 KB Output is correct
30 Correct 176 ms 47644 KB Output is correct
31 Correct 233 ms 50700 KB Output is correct
32 Correct 49 ms 37800 KB Output is correct
33 Correct 69 ms 40408 KB Output is correct
34 Correct 3 ms 37668 KB Output is correct
35 Correct 3 ms 37668 KB Output is correct
36 Correct 3 ms 37668 KB Output is correct
37 Correct 6 ms 37668 KB Output is correct
38 Correct 3 ms 37668 KB Output is correct
39 Correct 3 ms 37536 KB Output is correct
40 Correct 3 ms 37536 KB Output is correct
41 Correct 6 ms 38064 KB Output is correct
42 Correct 6 ms 38064 KB Output is correct
43 Correct 9 ms 38064 KB Output is correct
44 Correct 13 ms 38328 KB Output is correct
45 Correct 46 ms 37800 KB Output is correct
46 Correct 63 ms 37800 KB Output is correct
47 Correct 46 ms 37932 KB Output is correct
48 Correct 46 ms 37800 KB Output is correct
49 Correct 46 ms 37800 KB Output is correct
50 Correct 76 ms 44016 KB Output is correct
51 Correct 79 ms 44536 KB Output is correct
52 Correct 249 ms 56256 KB Output is correct
53 Correct 223 ms 55548 KB Output is correct
54 Correct 229 ms 54468 KB Output is correct
55 Correct 376 ms 63480 KB Output is correct
56 Correct 3266 ms 286808 KB Output is correct
57 Correct 756 ms 101832 KB Output is correct
58 Correct 729 ms 98544 KB Output is correct
59 Correct 676 ms 98016 KB Output is correct