답안 #1075825

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075825 2024-08-26T09:20:35 Z Abito 고대 책들 (IOI17_books) C++17
0 / 100
0 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)] || sz[getpar(i)]==1) continue;
		x=i*2-2;
		vis[getpar(i)]=1;
	}
	return x+ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -