답안 #73414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73414 2018-08-28T08:39:59 Z Navick 고대 책들 (IOI17_books) C++17
12 / 100
4 ms 620 KB
#include <bits/stdc++.h>
#include "books.h"

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;

const int maxN = 1e6 + 10;

bool mark[maxN];
vector <pii> que;

bool cmp(pii A, pii B)
{
	return make_pair(A.F, -A.S) < make_pair(B.F, -B.S);
}

long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size(), m = 0;
	ll ans = 0;

	for (int i=0; i<n; i++)
	{
		if(mark[i]) continue ;
		int curr = i, mn = n, sz = 0, mx = 0;

		while(!mark[curr])
		{
			mn = min(mn, curr);
			mx = max(mx, curr);
			sz ++;
			mark[curr] = true;
			ans += abs(p[curr] - curr);
			curr = p[curr];
		}
		if(mx != mn) que.pb({mn, mx});
	}

	sort(que.begin(), que.end(), cmp);
	int len = que.size();

	int maxR = -1;

	for (int i=0; i<len; i++)
	{
		if(maxR < que[i].F) m = que[i].F;
		maxR = max(maxR, que[i].S);
	}

	return ans + 2LL * m;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 3 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 3 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Incorrect 2 ms 620 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 3 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Incorrect 2 ms 620 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 620 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 252 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 2 ms 560 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 3 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Incorrect 2 ms 620 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -