답안 #436112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436112 2021-06-24T09:01:22 Z cfalas 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 204 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
#define len(x) ((int)x.size())

int t, n;
vi a, b;
int s;

vi p;

vector<int> adj;


long long minimum_walk(std::vector<int> pp, int ss) {
	s = ss;
	p = pp;
	int n = pp.size();
	ll ans=0;
	adj.resize(n);
	FOR(i,n){
		adj[i] = (p[i]);
	}
	vector<bool> vis(n, 0);
	int p =ss;
	FOR(i,n){
		if(vis[i]) continue;
		ll loops=abs(adj[i]-i);
		int q = adj[i];
		//cout<<i<<": ";
		while(q!=i){
			//cout<<q<<" ";
			loops += abs(adj[q]-q);
			vis[q] = true;
			q = adj[q];
		}
		//cout<<endl;
		ans+=loops;
		ans+=abs(p-i);
		p = i;
	}
	ans+=p;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5161'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -