답안 #1045288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045288 2024-08-05T19:59:10 Z beaconmc 고대 책들 (IOI17_books) C++14
0 / 100
0 ms 348 KB
#include "books.h"

#include <bits/stdc++.h>

 
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;


long long minimum_walk(vector<int> p, int s) {
	ll ans = 0;
	ll prev = s;

	int cur = -1;
	ll lo=0, hi=p.size()-1;
	while (lo < hi){

		while (p[lo] == lo && lo < hi){
			lo++;
		}
		while (p[hi] == hi && lo < hi){
			hi--;
		}
		if (!(lo<hi)) break;

		ans += abs(prev-lo);
		prev = lo;

		
		FOR(i,lo,hi+1){
			if (p[i] > cur){
				swap(p[i], cur);
			}else if (cur == i){
				swap(p[i],cur);
			}
		}

		ans += (hi-lo);
		FORNEG(i, hi, lo-1){
			if (p[i] < cur){
				swap(p[i], cur);
			}else if (cur == i){
				swap(p[i],cur);
			}
		}
		ans += (hi-lo);
	}
	ans += abs(0-prev);

	return ans;


}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '6361'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -