답안 #68011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68011 2018-08-15T18:27:59 Z KLPP 고대 책들 (IOI17_books) C++14
50 / 100
1649 ms 266724 KB
#include "books.h"
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long lld;
int arr[1000000];
int n;
int maxa,maxb;
int STm[1000000][32];
int STM[1000000][32];
int minimo(int i, int j){
	int size=j-i+1;
	int ans=10000000;
	int x=0;
	for(;(1<<(x+1))<=size;x++){
	}
	return min(STm[i][x],STm[j-(1<<x)+1][x]);
}
int maximo(int i, int j){
	int size=j-i+1;
	int ans=10000000;
	int x=0;
	for(;(1<<(x+1))<=size;x++){
	}
	return max(STM[i][x],STM[j-(1<<x)+1][x]);
}
lld computevalue(int i, int j){
    	//cout<<i<<" "<<j<<endl;
    	if(i<=maxa && maxb<=j)return 0;
    	int start=i;
    	int end=j;
    	int newstart=start;
    	int newend=end;
    	do{
    		//cout<<start<<" "<<end<<endl;
    		start=newstart;
    		end=newend;
    		newstart=min(start,minimo(start,end));
		newend=max(end,maximo(start,end));
    	}while(!(newstart==start && newend==end));
    	if(start>maxa){
    		return computevalue(start-1,end)+2;
    	}
    	else if(end<maxb){
    		return computevalue(start,end+1)+2;
    	}
    	return 0;
}
lld abs(lld x){
    	if(x>0)return x;
    	return -x;
}
long long minimum_walk(std::vector<int> p, int s) {
    	n=p.size();
    	for(int i=0;i<n;i++){
    		arr[i]=p[i];
    	}
    	maxa=n;
    	for(int i=0;i<n;i++){
    		if(p[i]!=i){
    			maxa=i;
    			i=n;
    		}
    	}
    	maxb=-1;
    	for(int i=n-1;i>-1;i--){
    		if(p[i]!=i){
    			maxb=i;
    			i=-1;
    		}
    	}
	for(int i=0;i<n;i++){
		STm[i][0]=arr[i];
		STM[i][0]=arr[i];
	}
	for(int j=1;j<32;j++){
		for(int i=0;i<n;i++){
			STm[i][j]=min(STm[i][j-1],STm[min(i+(1<<(j-1)),n-1)][j-1]);
			STM[i][j]=max(STM[i][j-1],STM[min(i+(1<<(j-1)),n-1)][j-1]);
			//cout<<STm[i][j]<<" "<<STM[i][j]<<endl;
		}
	}
	
	lld ans=0;
    	for(int i=0;i<n;i++)ans+=abs(p[i]-i);
    	//cout<<ans<<endl;
    	ans+=computevalue(s,s);
    	return ans;
}

Compilation message

books.cpp: In function 'int minimo(int, int)':
books.cpp:14:6: warning: unused variable 'ans' [-Wunused-variable]
  int ans=10000000;
      ^~~
books.cpp: In function 'int maximo(int, int)':
books.cpp:22:6: warning: unused variable 'ans' [-Wunused-variable]
  int ans=10000000;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 3 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 2 ms 712 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 3 ms 712 KB Output is correct
16 Correct 2 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 3 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 2 ms 712 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 3 ms 712 KB Output is correct
16 Correct 2 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 4 ms 892 KB Output is correct
23 Correct 2 ms 996 KB Output is correct
24 Correct 4 ms 996 KB Output is correct
25 Correct 3 ms 996 KB Output is correct
26 Correct 3 ms 996 KB Output is correct
27 Correct 4 ms 996 KB Output is correct
28 Correct 2 ms 996 KB Output is correct
29 Correct 3 ms 996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 3 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 2 ms 712 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 3 ms 712 KB Output is correct
16 Correct 2 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 4 ms 892 KB Output is correct
23 Correct 2 ms 996 KB Output is correct
24 Correct 4 ms 996 KB Output is correct
25 Correct 3 ms 996 KB Output is correct
26 Correct 3 ms 996 KB Output is correct
27 Correct 4 ms 996 KB Output is correct
28 Correct 2 ms 996 KB Output is correct
29 Correct 3 ms 996 KB Output is correct
30 Correct 1513 ms 262852 KB Output is correct
31 Correct 1473 ms 262852 KB Output is correct
32 Correct 1513 ms 262852 KB Output is correct
33 Correct 1553 ms 262872 KB Output is correct
34 Correct 1593 ms 266576 KB Output is correct
35 Correct 1649 ms 266712 KB Output is correct
36 Correct 1629 ms 266712 KB Output is correct
37 Correct 1504 ms 266712 KB Output is correct
38 Correct 1513 ms 266712 KB Output is correct
39 Correct 1484 ms 266724 KB Output is correct
40 Correct 1430 ms 266724 KB Output is correct
41 Correct 1486 ms 266724 KB Output is correct
42 Correct 1563 ms 266724 KB Output is correct
43 Correct 1536 ms 266724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 266724 KB Output is correct
2 Correct 3 ms 266724 KB Output is correct
3 Correct 3 ms 266724 KB Output is correct
4 Correct 3 ms 266724 KB Output is correct
5 Correct 4 ms 266724 KB Output is correct
6 Incorrect 4 ms 266724 KB 3rd lines differ - on the 1st token, expected: '22140', found: '22144'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 3 ms 712 KB Output is correct
11 Correct 3 ms 712 KB Output is correct
12 Correct 3 ms 712 KB Output is correct
13 Correct 2 ms 712 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 3 ms 712 KB Output is correct
16 Correct 2 ms 712 KB Output is correct
17 Correct 3 ms 712 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 4 ms 892 KB Output is correct
23 Correct 2 ms 996 KB Output is correct
24 Correct 4 ms 996 KB Output is correct
25 Correct 3 ms 996 KB Output is correct
26 Correct 3 ms 996 KB Output is correct
27 Correct 4 ms 996 KB Output is correct
28 Correct 2 ms 996 KB Output is correct
29 Correct 3 ms 996 KB Output is correct
30 Correct 1513 ms 262852 KB Output is correct
31 Correct 1473 ms 262852 KB Output is correct
32 Correct 1513 ms 262852 KB Output is correct
33 Correct 1553 ms 262872 KB Output is correct
34 Correct 1593 ms 266576 KB Output is correct
35 Correct 1649 ms 266712 KB Output is correct
36 Correct 1629 ms 266712 KB Output is correct
37 Correct 1504 ms 266712 KB Output is correct
38 Correct 1513 ms 266712 KB Output is correct
39 Correct 1484 ms 266724 KB Output is correct
40 Correct 1430 ms 266724 KB Output is correct
41 Correct 1486 ms 266724 KB Output is correct
42 Correct 1563 ms 266724 KB Output is correct
43 Correct 1536 ms 266724 KB Output is correct
44 Correct 2 ms 266724 KB Output is correct
45 Correct 3 ms 266724 KB Output is correct
46 Correct 3 ms 266724 KB Output is correct
47 Correct 3 ms 266724 KB Output is correct
48 Correct 4 ms 266724 KB Output is correct
49 Incorrect 4 ms 266724 KB 3rd lines differ - on the 1st token, expected: '22140', found: '22144'
50 Halted 0 ms 0 KB -