답안 #1072220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072220 2024-08-23T15:42:33 Z DeathIsAwe 고대 책들 (IOI17_books) C++17
50 / 100
159 ms 42476 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
bool visited[1000005];
bool visitedgroup[1000005];

long long minimum_walk(vector<int> p, int s) {
	if (s != 0) {return 0;}
	int n = p.size();
	while (n > 0) {
		if (p[n - 1] == n - 1) {
			n--;
		} else {
			break;
		}
	}
	if (n == 0) {
		return 0;
	}
	vector<long long> right(n), dist(n), group(n);
	
	for (int i=0;i<n;i++) {
		visitedgroup[i] = false;
		visited[i] = false;
		dist[i] = 0;
	}
	long long dummer, distcount, maxtrack, groupnum = 0;
	vector<int> temp;
	for (int i=0;i<n;i++) {
		if (visited[i]) {continue;}
		temp.clear();
		dummer = p[i];
		distcount = abs(i - p[i]);
		maxtrack = max(i, p[i]);
		temp.push_back(i);
		while (dummer != i) {
			distcount += abs(dummer - p[dummer]);
			maxtrack = max(maxtrack, (long long)p[dummer]);
			temp.push_back(dummer);
			dummer = p[dummer];
		}
		for (int j: temp) {
			right[j] = maxtrack;
			dist[j] = distcount;
			group[j] = groupnum;
			visited[j] = true;
		}
		groupnum++;
	}
	//for (int i=0;i<n;i++) {
	//	cout << right[i] << ' ';
	//} cout << '\n';
	//for (int i=0;i<n;i++) {
	//	cout << dist[i] << ' ';
	//} cout << '\n';
	

	long long ans = -2, dum = 0;
	while (dum < n) {
		dummer = dum;
		distcount = dist[dum];
		visitedgroup[group[dum]] = true;
		dum = right[dum];
		while (dummer < dum) {
			dummer++;
			if (visitedgroup[group[dummer]]) {continue;}
			distcount += dist[dummer];
			visitedgroup[group[dummer]] = true;
			dum = max(dum, right[dummer]);
		}
		ans += 2 + distcount;
		dum++;
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 408 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 408 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 159 ms 37740 KB Output is correct
31 Correct 125 ms 42476 KB Output is correct
32 Correct 73 ms 14928 KB Output is correct
33 Correct 100 ms 40528 KB Output is correct
34 Correct 89 ms 40276 KB Output is correct
35 Correct 99 ms 40272 KB Output is correct
36 Correct 91 ms 40272 KB Output is correct
37 Correct 124 ms 40444 KB Output is correct
38 Correct 104 ms 40312 KB Output is correct
39 Correct 98 ms 40276 KB Output is correct
40 Correct 95 ms 40788 KB Output is correct
41 Correct 108 ms 42472 KB Output is correct
42 Correct 99 ms 41592 KB Output is correct
43 Correct 89 ms 40276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 408 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 159 ms 37740 KB Output is correct
31 Correct 125 ms 42476 KB Output is correct
32 Correct 73 ms 14928 KB Output is correct
33 Correct 100 ms 40528 KB Output is correct
34 Correct 89 ms 40276 KB Output is correct
35 Correct 99 ms 40272 KB Output is correct
36 Correct 91 ms 40272 KB Output is correct
37 Correct 124 ms 40444 KB Output is correct
38 Correct 104 ms 40312 KB Output is correct
39 Correct 98 ms 40276 KB Output is correct
40 Correct 95 ms 40788 KB Output is correct
41 Correct 108 ms 42472 KB Output is correct
42 Correct 99 ms 41592 KB Output is correct
43 Correct 89 ms 40276 KB Output is correct
44 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
45 Halted 0 ms 0 KB -