답안 #581792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581792 2022-06-23T06:28:22 Z alireza_kaviani 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define sep			' '
#define X			first
#define Y			second
#define all(x)		(x).begin() , (x).end()
#define SZ(x)		int(x.size())

const int MAXN = 1e6 + 10;

ll n , s , sum , P[MAXN] , mark[MAXN];

ll minimum_walk(vector<int> p, int S) {
	n = SZ(p); s = S;
	for(int i = 0 ; i < n ; i++){
		P[i] = p[i];
		sum += abs(P[i] - i);
	}
	vector<pii> vec;
	while(n > 0 && P[n - 1] == n - 1)	n--;
	for(int i = 0 ; i < n ; i++){
		if(!mark[i]){
			int mn = MAXN , mx = 0 , x = i;
			while(!mark[x]){
				mark[x] = 1;
				mn = min(mn , x);
				mx = max(mx , x);
				x = P[x];
			}
			vec.push_back({mn , mx});
		}
	}
	sort(all(vec));
	vector<int> comps;
	for(pii i : vec){
		if(SZ(comps) == 0 || comps.back() < i.X){
			comps.push_back(i.Y);
		}
		else{
			comps[SZ(comps) - 1] = max(comps.back() , i.Y);
		}
	}

	return sum + SZ(comps) * 2 - 2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -