답안 #542828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542828 2022-03-28T07:27:09 Z zggf 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 212 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> parent, ranga;

int find(int x){
	if(parent[x]==-1) return x;
	parent[x] = find(parent[x]);
	return parent[x];
}

void join(int a, int b){
	a = find(a);
	b = find(b);
	if(a==b) return;
	if(ranga[a]>ranga[b]){
		parent[b] = a;
	}else if(ranga[b]>ranga[a]){
		parent[a] = b;
	}else{
		parent[b] = a;
		ranga[a]++;
	}
}

long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size();
	vector<int> odw(n);
	parent.resize(n, -1);
	ranga.resize(n);
	long long wyn = 0;
	vector<pair<int, int>> inp;
	for(int i = 0; i < n; i++){
		int pt = i;
		if(!odw[pt]){
			if(p[pt]!=pt){
				int mini = 1e9;
				int maxi = -1e9;
				while(!odw[pt]){
					mini = min(mini, pt);
					maxi = max(maxi, pt);
					odw[pt] = true;
					wyn+=abs(p[pt]-pt);
					pt = p[pt];	
				}
				inp.push_back({mini, maxi});
			}else{
			       	odw[pt] = true;
			}
		}
	}
	inp.push_back({s, s});
	sort(inp.begin(), inp.end());
	int dal = 0;
	for(int i = 0; i < inp.size()-1; i++){
		dal = max(dal, inp[i].second);
		while(inp[i+1].first<dal){
			i++;
			dal = max(dal, inp[i].second);
			if(i==n-1) break;
		}
		if(i<n-1){
			wyn+=2*(inp[i+1].first-dal);	
		}
	}
	return wyn;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0; i < inp.size()-1; i++){
      |                 ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '-965973816'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '-965973816'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '-965973816'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '70828'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '-965973816'
7 Halted 0 ms 0 KB -