답안 #748865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748865 2023-05-27T05:50:37 Z wenqi 고대 책들 (IOI17_books) C++17
50 / 100
245 ms 53052 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)
{
	P = p;
	ll sum = 0;
	int n = p.size();
	vector<pair<int, int>> q;
	q.push_back({s, s});
	bool lol = false;
	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()});
		auto [a, b] = q.back();
		if (a <= s and s <= b)
			lol = true;
	}
	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);
		}
	}
	int mn = 1e9;
	for (int i = 0; i < n; i++)
		if (seen[i])
			mn = min(mn, abs(i - s));
	if (lol)
		sum += 2 * mn;
	return sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 292 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 292 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 245 ms 53052 KB Output is correct
31 Correct 240 ms 33008 KB Output is correct
32 Correct 97 ms 12172 KB Output is correct
33 Correct 106 ms 15040 KB Output is correct
34 Correct 110 ms 15076 KB Output is correct
35 Correct 112 ms 15012 KB Output is correct
36 Correct 116 ms 15236 KB Output is correct
37 Correct 168 ms 13620 KB Output is correct
38 Correct 135 ms 13572 KB Output is correct
39 Correct 141 ms 13636 KB Output is correct
40 Correct 166 ms 15300 KB Output is correct
41 Correct 203 ms 30268 KB Output is correct
42 Correct 191 ms 21316 KB Output is correct
43 Correct 109 ms 15408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 292 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 245 ms 53052 KB Output is correct
31 Correct 240 ms 33008 KB Output is correct
32 Correct 97 ms 12172 KB Output is correct
33 Correct 106 ms 15040 KB Output is correct
34 Correct 110 ms 15076 KB Output is correct
35 Correct 112 ms 15012 KB Output is correct
36 Correct 116 ms 15236 KB Output is correct
37 Correct 168 ms 13620 KB Output is correct
38 Correct 135 ms 13572 KB Output is correct
39 Correct 141 ms 13636 KB Output is correct
40 Correct 166 ms 15300 KB Output is correct
41 Correct 203 ms 30268 KB Output is correct
42 Correct 191 ms 21316 KB Output is correct
43 Correct 109 ms 15408 KB Output is correct
44 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -