답안 #70444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70444 2018-08-22T22:44:12 Z bnahmad15 고대 책들 (IOI17_books) C++17
0 / 100
3 ms 604 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();
	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];
		points.push_back(0);
		for(int i = 0;i<v.size();i++){
			res += 1LL * v[i].second;
			long long mn = -1;
			for(int j = 0;j<v[i].first.size();j++){
				for(int k = 0;k<points.size();k++){
					if(mn == -1)
						mn = 1LL * abs(points[k] - v[i].first[j]);
					mn = min(mn,1LL * abs(points[k] - v[i].first[j]));
				}
			}
			res += mn * 2LL;
			for(int j = 0;j<v[i].first.size();j++)
				points.push_back(v[i].first[j]);
			sort(points.begin(),points.end());
		}
	}
	return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<v.size();i++){
                 ~^~~~~~~~~
books.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 0;j<v[i].first.size();j++){
                  ~^~~~~~~~~~~~~~~~~~
books.cpp:35:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k = 0;k<points.size();k++){
                   ~^~~~~~~~~~~~~~
books.cpp:42:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 0;j<v[i].first.size();j++)
                  ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Incorrect 3 ms 604 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Incorrect 3 ms 604 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Incorrect 3 ms 604 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 604 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4096'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Incorrect 3 ms 604 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -