답안 #70451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70451 2018-08-22T23:01:05 Z bnahmad15 고대 책들 (IOI17_books) C++17
12 / 100
3 ms 740 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;

int n;
bool vis[N];
vector<pair<vector<int>,long long> > v;
vector<int> points;
long long minimum_walk(std::vector<int> p, int s) {
	n = p.size();
//	do{
	for(int i = 0;i<n;i++)
		vis[i] = 0;
	v.clear();
	points.clear();
	for(int i = 0;i<n;i++){
		if(p[i] != i && vis[i] == false){
			v.push_back(make_pair(vector<int>(),0));
			v.back().first.push_back(i);
			vis[i] = true;
			v.back().second += 1LL * abs(p[i] - i);
			int j = p[i];
			while (j != i){
				vis[j] = true;
				v.back().first.push_back(j);
				v.back().second += 1LL * abs(p[j] - j);
				j = p[j];
			}
		}
	}
	long long res = 0;
	if(v.size()){
		res = 2 * v[0].first[0];
		for(int i = 0;i<v.size();i++){
			res += 1LL * v[i].second;
			sort(v[i].first.begin(),v[i].first.end());
		}
		for(int i = 1;i<v.size();i++){
			if(v[i].first[0] <= v[i-1].first.back())
				continue;
			res += 2LL * abs(v[i].first[0] - v[i-1].first.back());
		}
	}
/*		for(int i = 0;i<4;i++)
			cout<<p[i]<<" ";
		cout<<res<<endl;*/
//	}while(next_permutation(p.begin(),p.end()));
	return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<v.size();i++){
                 ~^~~~~~~~~
books.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1;i<v.size();i++){
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 544 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 544 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 3 ms 740 KB Output is correct
22 Incorrect 2 ms 740 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2104'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 544 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 3 ms 740 KB Output is correct
22 Incorrect 2 ms 740 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2104'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 740 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4072'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 544 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 3 ms 740 KB Output is correct
22 Incorrect 2 ms 740 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2104'
23 Halted 0 ms 0 KB -