답안 #748850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748850 2023-05-27T05:24:35 Z wenqi 고대 책들 (IOI17_books) C++17
50 / 100
237 ms 52812 KB
#include "books.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>

using namespace std;
using ll = long long;

bool seen[1000005];
vector<int> P;
vector<int> t;

ll dfs(int i)
{
	if (seen[i])
		return 0;
	seen[i] = true;
	t.push_back(i);
	return abs(i - P[i]) + dfs(P[i]);
}

ll minimum_walk(vector<int> p, int s)
{
	memset(seen, 0, sizeof(seen));
	P = p;
	ll sum = 0;
	int n = p.size();
	vector<pair<int, int>> q;
	q.push_back({s, s});
	for (int i = 0; i < n; i++)
	{
		if (seen[i] or i == p[i])
			continue;
		t.clear();
		sum += dfs(i);
		sort(t.begin(), t.end());
		q.push_back({t.front(), t.back()});
	}
	sort(q.begin(), q.end());
	int lt = -1;
	for (auto [a, b] : q)
	{
		if (lt == -1)
		{
			lt = b;
		}
		if (a > lt)
		{
			sum += 2 * (a - lt);
			lt = b;
		}
		else
		{
			lt = max(lt, b);
		}
	}
	return sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 237 ms 52812 KB Output is correct
31 Correct 228 ms 32740 KB Output is correct
32 Correct 86 ms 12904 KB Output is correct
33 Correct 95 ms 15080 KB Output is correct
34 Correct 101 ms 15076 KB Output is correct
35 Correct 101 ms 15068 KB Output is correct
36 Correct 107 ms 15076 KB Output is correct
37 Correct 120 ms 13412 KB Output is correct
38 Correct 136 ms 13352 KB Output is correct
39 Correct 140 ms 13284 KB Output is correct
40 Correct 152 ms 15056 KB Output is correct
41 Correct 193 ms 30188 KB Output is correct
42 Correct 184 ms 21236 KB Output is correct
43 Correct 98 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1236 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 237 ms 52812 KB Output is correct
31 Correct 228 ms 32740 KB Output is correct
32 Correct 86 ms 12904 KB Output is correct
33 Correct 95 ms 15080 KB Output is correct
34 Correct 101 ms 15076 KB Output is correct
35 Correct 101 ms 15068 KB Output is correct
36 Correct 107 ms 15076 KB Output is correct
37 Correct 120 ms 13412 KB Output is correct
38 Correct 136 ms 13352 KB Output is correct
39 Correct 140 ms 13284 KB Output is correct
40 Correct 152 ms 15056 KB Output is correct
41 Correct 193 ms 30188 KB Output is correct
42 Correct 184 ms 21236 KB Output is correct
43 Correct 98 ms 15184 KB Output is correct
44 Incorrect 1 ms 1236 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -