답안 #1048282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048282 2024-08-08T06:22:03 Z LittleOrange 고대 책들 (IOI17_books) C++17
0 / 100
0 ms 348 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
long long minimum_walk(std::vector<int> p, int s) {
	ll ans = 0;
	ll n = p.size();
	/*
	if (s == 0){
		vector<ll> u(n,0);
		for(ll i = 0;i<n;i++){
			if(p[i]!=i){
				ans += i-s;
				s = i;
				ll x = i;
				do{
					ans += abs(p[x]-x);
					ll y = x;
					x = p[x];
					p[y] = y;
				} while(x!=i);
			}
		}
		ans += s;
	}*/
	ll gpc = 0;
	vector<ll> gp(n,-1);
	vector<vector<ll>> gps;
	for(ll i = 0;i<n;i++){
		if (gp[i]==-1){
			ll cur = gpc++;
			gps.emplace_back();
			ll x = i;
			do{
				gp[x] = cur;
				gps[cur].push_back(x);
				ans += abs(p[x]-x);
				x = p[x];
			} while(x!=i);
		}
	}
	ans += (gpc-1)*2;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4186'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -