답안 #351786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
351786 2021-01-20T07:49:43 Z amunduzbaev Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 364 KB
#include "shortcut.h"
#include <bits/stdc++.h>

#ifndef EVAL
#include "grader.cpp"
#endif

using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
//#define int long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vll vector<ll>
#define vii vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define cnt(a)__builtin_popcount(a)
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
 
const int N = 2e3+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);

int used[N], nn;
ll diam, last;
vpii edges[N]; 

void djk(){
	priority_queue<pii> qq;
	qq.push({0, 0});
	vll dis(last, inf);
	dis[0] = 0;
	while(!qq.empty()){
		pii cur = qq.top(); qq.pop();
		int u = cur.ss;
		//cout<<u<<"\n";
		if(dis[u] < -cur.ss) continue;
		//used[u] = 1;
		for(auto x:edges[u]){
			//if(used[x.ff]) continue;
			if(dis[x.ff] > dis[u] + x.ss){
				dis[x.ff] = dis[u] + x.ss;
				qq.push({ - dis[x.ff], x.ff});
			}
		}
	}
	//for(int i=0;i<nn;i++) cout<<dis[i]<<" ";
	//cout<<"\n";
	
	int d1 = 0;
	for(int i=0;i<last;i++) if(dis[d1] < dis[i]) d1 = i;
	
	qq.push({0, d1});
	dis.assign(last, inf);
	dis[d1] = 0;
	while(!qq.empty()){
		pii cur = qq.top(); qq.pop(); 
		int u = cur.ss;
		//cout<<u<<"\n";
		if(dis[u] < -cur.ss) continue;
		//used[u] = 1;
		for(auto x:edges[u]){
			//if(used[x.ff]) continue;
			if(dis[x.ff] > dis[u] + x.ss){
				dis[x.ff] = dis[u] + x.ss;
				qq.push({ - dis[x.ff], x.ff});
			}
		}
	}
	
	//for(int i=0;i<nn;i++) cout<<dis[i]<<" ";
	//cout<<"\n";
	
	int d2 = 0;
	for(int i=0;i<last;i++) if(dis[d2] < dis[i]) d2 = i;
	
	//cout<<d1<<" "<<d2<<" "<<dis[d2]<<"\n";
	
	diam = dis[d2];
}

/*

4 10
10 20 20 
0 40 0 30 

*/

ll find_shortcut(int n, vector<int> l, vector<int> d, int c){
	for(int i=0;i<n-1;i++){
		edges[i].pb({i+1, l[i]});
		edges[i+1].pb({i, l[i]});
	}
	last = n;
	nn = n;
	for(int i=0;i<n;i++){
		if(d[i] == 0) continue;
		edges[last].pb({i, d[i]});
		edges[i].pb({last++, d[i]});
	}
	//for(int i=0;i<n;i++){
		//for(auto x : edges[i]) cout<<i<<" "<<x.ff<<" "<<x.ss<<"\n";
	//}
	djk();
	diam = inf;
	ll ans = inf;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			edges[i].pb({j, c});
			edges[j].pb({j, c});
			ll tmp = diam;
			djk();
			//cout<<i<<" "<<j<<" ";
			//cout<<diam<<endl;
			ans = min(ans, diam);
			diam = tmp;
			edges[i].pop_back();
			edges[j].pop_back();
		}
	}
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 21 vs contestant 22
4 Halted 0 ms 0 KB -