답안 #1048312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048312 2024-08-08T06:41:17 Z LittleOrange 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 348 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct obj{
	ll i,w;
	bool operator<(const obj &o)const{
		return w>o.w;
	}
};
long long minimum_walk(std::vector<int> p, int s) {
	ll ans = 0;
	ll n = p.size();
	/*
	if (s == 0){
		vector<ll> u(n,0);
		for(ll i = 0;i<n;i++){
			if(p[i]!=i){
				ans += i-s;
				s = i;
				ll x = i;
				do{
					ans += abs(p[x]-x);
					ll y = x;
					x = p[x];
					p[y] = y;
				} while(x!=i);
			}
		}
		ans += s;
	}*/
	ll gpc = 0;
	vector<ll> gp(n,-1);
	vector<vector<ll>> gps;
	for(ll i = 0;i<n;i++){
		if (gp[i]==-1){
			ll cur = gpc++;
			gps.emplace_back();
			ll x = i;
			do{
				gp[x] = cur;
				gps[cur].push_back(x);
				ans += abs(p[x]-x);
				x = p[x];
			} while(x!=i);
		}
	}
	vector<ll> cost(n,n);
	priority_queue<obj> q;
	q.push({s,0});
	vector<ll> vis(gpc,0);
	while(!q.empty()){
		auto [i,w] = q.top();q.pop();
		//cerr << i << " " << w << endl;
		if (cost[i]<=w) continue;
		cost[i] = w;
		if(i>0) q.push({i-1,w+1});
		if(i<n-1) q.push({i+1,w+1});
		if (!vis[gp[i]]){
			vis[gp[i]] = 1;
			if (gps[gp[i]].size()>1) ans += cost[i]*2;
			for(ll j : gps[gp[i]]){
				q.push({j,0});
			}
		}
	}
	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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3106'
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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -