Submission #68000

# Submission time Handle Problem Language Result Execution time Memory
68000 2018-08-15T17:56:14 Z KLPP Ancient Books (IOI17_books) C++14
22 / 100
634 ms 42840 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;
lld DP[1000][1000];
lld computevalue(int i, int j){
	//cout<<i<<" "<<j<<endl;
	if(i<=maxa && maxb<=j)return 0;
	if(DP[i][j]!=-1)return DP[i][j];
	int start=i;
	int end=j;
	int newstart=start;
	int newend=end;
	do{
		//cout<<start<<" "<<end<<endl;
		start=newstart;
		end=newend;
		for(int x=start;x<=end;x++){
			newstart=min(newstart,arr[x]);
			newend=max(newend,arr[x]);
		}
	}while(!(newstart==start && newend==end));
	DP[i][j]=1000000000000000000;
	if(start>maxa){
		DP[i][j]=min(DP[i][j],computevalue(start-1,end)+2);
	}
	else if(end<maxb){
		DP[i][j]=min(DP[i][j],computevalue(start,end+1)+2);
	}else DP[i][j]=0;
	return DP[i][j];
}
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++){
		for(int j=0;j<n;j++){
			DP[i][j]=-1;
		}
	}
	//cout<<maxa<<" "<<maxb<<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;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 2 ms 668 KB Output is correct
10 Correct 3 ms 736 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 740 KB Output is correct
15 Correct 3 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 2 ms 668 KB Output is correct
10 Correct 3 ms 736 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 740 KB Output is correct
15 Correct 3 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
19 Correct 10 ms 8500 KB Output is correct
20 Correct 9 ms 8504 KB Output is correct
21 Correct 10 ms 8512 KB Output is correct
22 Correct 9 ms 8512 KB Output is correct
23 Correct 10 ms 8516 KB Output is correct
24 Correct 11 ms 8516 KB Output is correct
25 Correct 10 ms 8516 KB Output is correct
26 Correct 10 ms 8516 KB Output is correct
27 Correct 10 ms 8520 KB Output is correct
28 Correct 9 ms 8536 KB Output is correct
29 Correct 11 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 2 ms 668 KB Output is correct
10 Correct 3 ms 736 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 740 KB Output is correct
15 Correct 3 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
19 Correct 10 ms 8500 KB Output is correct
20 Correct 9 ms 8504 KB Output is correct
21 Correct 10 ms 8512 KB Output is correct
22 Correct 9 ms 8512 KB Output is correct
23 Correct 10 ms 8516 KB Output is correct
24 Correct 11 ms 8516 KB Output is correct
25 Correct 10 ms 8516 KB Output is correct
26 Correct 10 ms 8516 KB Output is correct
27 Correct 10 ms 8520 KB Output is correct
28 Correct 9 ms 8536 KB Output is correct
29 Correct 11 ms 8536 KB Output is correct
30 Runtime error 634 ms 42840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 42840 KB Output is correct
2 Correct 10 ms 42840 KB Output is correct
3 Correct 10 ms 42840 KB Output is correct
4 Correct 10 ms 42840 KB Output is correct
5 Correct 10 ms 42840 KB Output is correct
6 Incorrect 9 ms 42840 KB 3rd lines differ - on the 1st token, expected: '22140', found: '22144'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 3 ms 536 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 668 KB Output is correct
9 Correct 2 ms 668 KB Output is correct
10 Correct 3 ms 736 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
13 Correct 4 ms 740 KB Output is correct
14 Correct 3 ms 740 KB Output is correct
15 Correct 3 ms 740 KB Output is correct
16 Correct 3 ms 740 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
19 Correct 10 ms 8500 KB Output is correct
20 Correct 9 ms 8504 KB Output is correct
21 Correct 10 ms 8512 KB Output is correct
22 Correct 9 ms 8512 KB Output is correct
23 Correct 10 ms 8516 KB Output is correct
24 Correct 11 ms 8516 KB Output is correct
25 Correct 10 ms 8516 KB Output is correct
26 Correct 10 ms 8516 KB Output is correct
27 Correct 10 ms 8520 KB Output is correct
28 Correct 9 ms 8536 KB Output is correct
29 Correct 11 ms 8536 KB Output is correct
30 Runtime error 634 ms 42840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Halted 0 ms 0 KB -