답안 #123174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123174 2019-06-30T09:48:02 Z SirCeness 고대 책들 (IOI17_books) C++14
50 / 100
296 ms 87008 KB
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define inf 1000000009
using namespace std;
typedef long long ll;

int n;
vector<int> arr;
vector<ll> numara;
vector<ll> beg;
vector<ll> en;
vector<pair<int, pair<int, int> > > edges;
int num = 0;
vector<pair<ll, ll> > minler;
vector<int> dsu;

int find(int node){
	if (dsu[node] == node) return node;
	int ans = find(dsu[node]);
	return dsu[node] = ans;
}

void unionn(int node1, int node2){
	node1 = find(node1);
	node2 = find(node2);
	if (node1 == node2) return;
	dsu[node1] = node2;
}

ll minimum_walk(vector<int> p, int s){
	arr = p;
	n = p.size();
	numara.resize(n);
	while (p[n-1] == n-1 && n > 1) n--;
	if (n == 1) return 0;
	int strt = 0;
	while (p[strt] == strt) strt++;
	ll ans = 0;
	for (int i = 0; i < n; i++) numara[i] = -1;
	for (int i = 0; i < n; i++){
		if (numara[i] == -1 && p[i] != i){
			int node = i;
			int lmost = node;
			int rmost = node;
			while (numara[node] == -1){
				numara[node] = num;
				ans += abs(p[node] - node);
				node = p[node];
				lmost = min(lmost, node);
				rmost = max(rmost, node);
			}
			beg.pb(lmost);
			en.pb(rmost);
			num++;
			//ans += (2*(rmost-lmost));
		}
	}
	
	//for (int i = 0; i < n; i++) cout << numara[i] << " "; cout << endl;
	
	vector<list<int> > begs(n);
	vector<list<int> > ens(n);
	for (int i = 0; i < num; i++){
		begs[beg[i]].pb(i);
		ens[en[i]].pb(i);
	}
	set<int> open;
	for (int i = strt; i < n; i++){
		for (list<int>::iterator it = begs[i].begin(); it != begs[i].end(); ++it){
			open.insert(*it);
		}
		for (list<int>::iterator it = ens[i].begin(); it != ens[i].end(); ++it){
			open.erase(open.find(*it));
		}
		if (open.size() == 0) ans += 2;
	}
	ans -= 2;
	
	int mindist = inf;
	for (int i = s; i < n; i++){
		if (numara[i] != -1){
			mindist = min(mindist, i-s);
			break;
		}
	}
	for (int i = s; i >= 0; i--){
		if (numara[i] != -1){
			mindist = min(mindist, s-i);
			break;
		}
	}
	ans += 2*mindist;
	
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 248 ms 68016 KB Output is correct
31 Correct 245 ms 68104 KB Output is correct
32 Correct 138 ms 21076 KB Output is correct
33 Correct 255 ms 83076 KB Output is correct
34 Correct 250 ms 83132 KB Output is correct
35 Correct 264 ms 84996 KB Output is correct
36 Correct 248 ms 80264 KB Output is correct
37 Correct 229 ms 70048 KB Output is correct
38 Correct 226 ms 68484 KB Output is correct
39 Correct 224 ms 68432 KB Output is correct
40 Correct 225 ms 67960 KB Output is correct
41 Correct 259 ms 67940 KB Output is correct
42 Correct 228 ms 67796 KB Output is correct
43 Correct 296 ms 87008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 400 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 248 ms 68016 KB Output is correct
31 Correct 245 ms 68104 KB Output is correct
32 Correct 138 ms 21076 KB Output is correct
33 Correct 255 ms 83076 KB Output is correct
34 Correct 250 ms 83132 KB Output is correct
35 Correct 264 ms 84996 KB Output is correct
36 Correct 248 ms 80264 KB Output is correct
37 Correct 229 ms 70048 KB Output is correct
38 Correct 226 ms 68484 KB Output is correct
39 Correct 224 ms 68432 KB Output is correct
40 Correct 225 ms 67960 KB Output is correct
41 Correct 259 ms 67940 KB Output is correct
42 Correct 228 ms 67796 KB Output is correct
43 Correct 296 ms 87008 KB Output is correct
44 Incorrect 2 ms 400 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -