| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 70450 | bnahmad15 | 고대 책들 (IOI17_books) | C++17 | 2057 ms | 21328 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
			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]));
					}
				}
				if(v[i].first[0] > points.back())
					res += 2 * mn;	
				for(int j = 0;j<v[i].first.size();j++)
					points.push_back(v[i].first[j]);
				sort(points.begin(),points.end());
			}
		}
/*		for(int i = 0;i<4;i++)
			cout<<p[i]<<" ";
		cout<<res<<endl;*/
//	}while(next_permutation(p.begin(),p.end()));
	return res;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
