답안 #429017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429017 2021-06-15T16:43:27 Z vanic 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 204 KB
#include "books.h"
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

int n;

ll minimum_walk(vector < int > p, int s) {
	n=p.size();
	ll br=0;
	int pos=0;
	int tren=-1;
	int l=0, d=n;
	bool pp=0;
	for(int i=0; i<n; i++){
		if(p[i]!=i){
			l=i;
			pp=1;
			break;
		}
	}
	if(!pp){
		return 0;
	}
	for(int i=n-1; i>-1; i--){
		if(p[i]!=i){
			d=i+1;
			break;
		}
	}
	while(l<d){
		br+=l-pos;
		pos=l;
		br+=(d-l-1)*2;
		for(int i=l; i<d; i++){
			if(p[i]!=i){
				if(tren<p[i]){
					swap(p[i], tren);
				}
			}
			else if(tren==i){
				swap(p[i], tren);
			}
		}
		for(int i=d-1; i>=l; i--){
			if(p[i]!=i){
				if(tren>p[i]){
					swap(p[i], tren);
				}
			}
			else if(tren==i){
				swap(p[i], tren);
			}
		}
		pp=0;
		for(int i=l; i<d; i++){
			if(p[i]!=i){
				l=i;
				pp=1;
				break;
			}
		}
		if(!pp){
			break;
		}
		for(int i=d-1; i>=l; i--){
			if(p[i]!=i){
				d=i+1;
				break;
			}
		}
	}
	br+=pos;
	return br;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5936'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -