답안 #429970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429970 2021-06-16T10:46:46 Z AmineWeslati 고대 책들 (IOI17_books) C++14
0 / 100
3 ms 4172 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)

//--------------------------------

const int MX=1e6+5;
int N; 
vi vis(MX,0);

int check(){
	FOR(i,0,N) if(!vis[i]) return i;
	return N;
}


ll minimum_walk(vi p, int s){
	N=sz(p);

	FOR(i,0,N) if(p[i]==i) vis[i]=1;

	ll ans=0;
	while(1){
		int idx=check();
		if(idx==N) break;

		ans+=abs(s-idx);

		while(1){
			if(vis[idx]) break;
			vis[idx]=1;
			ans+=abs(idx-p[idx]);
			idx=p[idx];
		}

		s=idx; 
	}
	ans+=abs(s);
	return ans; 
}

/*

4 0
0 2 3 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 3 ms 4172 KB Output is correct
3 Correct 3 ms 4172 KB Output is correct
4 Correct 3 ms 4172 KB Output is correct
5 Correct 3 ms 4172 KB Output is correct
6 Incorrect 3 ms 4172 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 3 ms 4172 KB Output is correct
3 Correct 3 ms 4172 KB Output is correct
4 Correct 3 ms 4172 KB Output is correct
5 Correct 3 ms 4172 KB Output is correct
6 Incorrect 3 ms 4172 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 3 ms 4172 KB Output is correct
3 Correct 3 ms 4172 KB Output is correct
4 Correct 3 ms 4172 KB Output is correct
5 Correct 3 ms 4172 KB Output is correct
6 Incorrect 3 ms 4172 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4120 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5153'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 3 ms 4172 KB Output is correct
3 Correct 3 ms 4172 KB Output is correct
4 Correct 3 ms 4172 KB Output is correct
5 Correct 3 ms 4172 KB Output is correct
6 Incorrect 3 ms 4172 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -