답안 #292945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292945 2020-09-07T14:56:12 Z amoo_safar 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 384 KB
#include "books.h"

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 1e6 + 10;

int mk[N];

ll minimum_walk(vector<int> p, int s) {
	int n = p.size();
	ll ans = 0;
	ll near = n;
	for(int i = 0; i < n; i++){
		if(p[i] != i){
			ans += abs(p[i] - i);
			near = min(near, (ll) abs(s - i));
		} else mk[i] = 1;
	}
	int com = 0;
	vector<pii> seg;
	for(int i = 0; i < n; i++){
		if(mk[i]) continue;
		com ++;
		vector<int> vis;
		int nw = i;
		while(!mk[nw]){
			mk[nw] = 1;
			vis.pb(nw);
			nw = p[nw];
		}
		sort(all(vis));
		seg.pb({vis[0], vis.back()});
	}
	if(com == 0) return 0;
	sort(all(seg));
	int mxr = seg[0].F;
	for(int i = 1; i < (int)seg.size(); i++){
		if(mxr < seg[i].F)
			ans += 2 * (seg[i].F - mxr);
		mxr = max(mxr, seg[i].S);
	}
	ans += 2 * near;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4064'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -