답안 #1075819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075819 2024-08-26T09:18:48 Z Abito 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 348 KB
#include "books.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
int a[N],par[N],sz[N],n;
bool vis[N];
int getpar(int x){
	if (x==par[x]) return x;
	return par[x]=getpar(par[x]);
}
void link(int x,int y){
	x=getpar(x);
	y=getpar(y);
	if (x==y) return;
	if (sz[x]>sz[y]) swap(x,y);
	sz[y]+=sz[x];
	par[x]=y;
}
long long minimum_walk(std::vector<int32_t> p, int32_t s) {
	n=p.size();int ans=0;
	for (int i=1;i<=n;i++) a[i]=p[i-1]+1,par[i]=i,sz[i]=1;
	for (int i=1;i<=n;i++) link(a[i],i),ans+=abs(a[i]-i);
	int x=0;
	for (int i=1;i<=n;i++){
		if (vis[getpar(i)]) continue;
		x=i*2-2;
		vis[getpar(i)]=1;
	}
	return x+ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 1 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 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 -