답안 #1023520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023520 2024-07-14T23:21:56 Z HappyCapybara 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 348 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long

vector<int> par, siz;

int find(int a){
	if (par[a] == a) return a;
	return par[a] = find(par[a]);
}

void merge(int a, int b){
	a = find(a);
	b = find(b);
	if (a == b) return;
	else par[a] = b;
	siz[b] += siz[a];
	siz[a] = 0;
}

ll minimum_walk(vector<int> p, int s){
	int n = p.size();
	par.resize(n);
	siz.resize(n, 1);
	for (int i=0; i<n; i++) par[i] = i;
	for (int i=0; i<n; i++) merge(i, p[i]);
	int res = -2;
	for (int i=0; i<n; i++){
		res += abs(p[i]-i);
		if (siz[i] > 1) res += 2;
	}
	if (siz[0] = 1) res += 2;
	return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:34:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   34 |  if (siz[0] = 1) res += 2;
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 0 ms 344 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 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3108'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 -