답안 #835138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835138 2023-08-23T09:00:52 Z oscar1f 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
#include "books.h"

using namespace std;
using ll=long long;

const ll MAX_TAILLE=1000*1000+5;
ll nbVal,rep,posDeb,nbCompo,valFin;
vector<ll> obj,listeCompo;
ll idCompo[MAX_TAILLE],finCompo[MAX_TAILLE];

void DFS(ll pos) {
	if (idCompo[pos]==0) {
		idCompo[pos]=nbCompo;
		finCompo[pos]=valFin;
		DFS(obj[pos]);
	}
}

ll minimum_walk(vector<int> p, int s) {
	posDeb=s;
	nbVal=p.size();
	for (auto i:p) {
		obj.push_back(i);
	}
	for (ll i=nbVal-1;i>=0;i--) {
		if (idCompo[i]==0) {
			nbCompo++;
			valFin=i;
			DFS(i);
		}
		rep+=abs(i-obj[i]);
	}
	int pos=0;
	while (pos!=nbVal-1) {
		if (finCompo[pos]==pos) {
			pos++;
			rep+=2;
		}
		else {
			pos=finCompo[pos];
		}
	}
	return rep;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -