답안 #1072213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072213 2024-08-23T15:39:30 Z DeathIsAwe 고대 책들 (IOI17_books) C++17
22 / 100
69 ms 21772 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<int> right(n), dist(n), group(n);
	
	for (int i=0;i<n;i++) {
		visitedgroup[i] = false;
		visited[i] = false;
		dist[i] = 0;
	}
  	if (n > 1000) {
      return 0;
    }
	int 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, p[dummer]);
			temp.push_back(dummer);
			dummer = p[dummer];
		}
		for (int j: temp) {
			right[j] = maxtrack;
			dist[j] = distcount;
			group[j] = groupnum;
		}
		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';
	if (n > 1000) {
		return 0;
	}
	

	int 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Incorrect 69 ms 21772 KB 3rd lines differ - on the 1st token, expected: '333035179244', found: '0'
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Incorrect 69 ms 21772 KB 3rd lines differ - on the 1st token, expected: '333035179244', found: '0'
31 Halted 0 ms 0 KB -