답안 #866408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866408 2023-10-26T05:03:03 Z GoldLight 악어의 지하 도시 (IOI11_crocodile) C++17
89 / 100
410 ms 66712 KB
#include <bits/stdc++.h>
using namespace std;
void fast(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
 
//const int NN=1e5;
const long long INF=1e18;
// int R[NN+1][2], L[NN+1], P[NN+1];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
	vector<pair<int,int>> v[N];
	for(int i=0; i<M; i++){
		v[R[i][0]].push_back({R[i][1], L[i]});
		v[R[i][1]].push_back({R[i][0], L[i]});
	}
	vector<vector<long long>> dist(N+2, vector<long long>(2, INF));
	priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<pair<long long,int>>> pq;
	for(int i=0; i<K; i++){
		dist[P[i]][0]=dist[P[i]][1]=0;
		pq.push({0, P[i]});
	}
	while(!pq.empty()){
		auto[d, u]=pq.top(); pq.pop();
		if(d>dist[u][1]) continue;
		for(auto [to, di]:v[u]){
			if(d+di<dist[to][1]){
				dist[to][1]=d+di;
				sort(dist[to].begin(), dist[to].end());
				if(dist[to][1]<INF) pq.push({dist[to][1], to});
			}
		}
	}
	return dist[0][1];
}
// int main(){
// 	fast();
// 	int n, m, k; cin>>n>>m>>k;
// 	for(int i=0; i<m; i++){
// 		cin>>R[i][0]>>R[i][1];
// 	}
// 	for(int i=0; i<m; i++) cin>>L[i];
// 	for(int i=0; i<k; i++) cin>>P[i];
// 	cout<<travel_plan(n, m, k);
// }
 
/*
#define int long long
const int INF=1e18;
signed main(){
	fast();
	int teskes; cin>>teskes;
	while(teskes--){
		int n, m, k; cin>>n>>m>>k;
		int a[n+1], now=0;
		for(int i=1; i<=n; i++) cin>>a[i];
		vector<pair<int,int>> v[n+1], to(2*k+5);
		vector<int> dp(2*k+5, -INF);
		dp[0]=0;
		v[1].push_back({1, now++});  
		for(int i=1; i<=k; i++){
			int a, b, c, d, h; cin>>a>>b>>c>>d>>h;
			v[a].push_back({b, now++});
			v[c].push_back({d, now++});
			to[now-2]={now-1, h};
		}
		v[n].push_back({m, now});
		for(int i=1; i<=n; i++){
			int sz=v[i].size();
			sort(v[i].begin(), v[i].end());
			for(int j=1; j<sz; j++){
				dp[v[i][j].second]=max(dp[v[i][j].second], dp[v[i][j-1].second]-(v[i][j].first-v[i][j-1].first)*a[i]);
			}
			for(int j=sz-2; j>=0; j--){
				dp[v[i][j].second]=max(dp[v[i][j].second], dp[v[i][j+1].second]-(v[i][j+1].first-v[i][j].first)*a[i]);
			}
			for(auto [r, num]:v[i]){
				if(to[num].first && dp[num]!=-INF){
					dp[to[num].first]=max(dp[to[num].first], dp[num]+to[num].second);
				}
			}
		}
		if(dp[now]==-INF) cout<<"NO ESCAPE";
		else cout<<-dp[now];
		cout<<'\n';
	}
}
*/
/*
#define int long long
const int INF=1e18, N=3e5;
signed main(){
	fast();
	int teskes; cin>>teskes;
	while(teskes--){
		int n, m, k; cin>>n>>m>>k;
		int a[n+1], num=2;
		for(int i=1; i<=n; i++) cin>>a[i];
		map<pair<int,int>, int> mp; mp[{1, 1}]=0, mp[{n, m}]=1;
		vector<pair<int,int>> v[N+1];
		priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
		pq.push({1, 1}), pq.push({n, m});
		for(int i=1; i<=k; i++){
			int p, q, r, s, h; cin>>p>>q>>r>>s>>h;
			if(!mp.count({p, q})) mp[{p, q}]=num++;
			if(!mp.count({r, s})) mp[{r, s}]=num++;
			v[mp[{p, q}]].push_back({mp[{r, s}], -h});
			pq.push({p, q});
			pq.push({r, s});
		}
		int la=pq.top().first, lb=pq.top().second; pq.pop();
		while(!pq.empty()){
			auto[na, nb]=pq.top(); pq.pop(); //new
			if(la==na && lb==nb) continue;
			if(la==na){
				v[mp[{la, lb}]].push_back({mp[{na, nb}], (nb-lb)*a[la]});
				v[mp[{na, nb}]].push_back({mp[{la, lb}], (nb-lb)*a[la]});
			}
			la=na, lb=nb;
		}
		vector<int> dist(num, INF);
		vector<bool> vis(num);
		dist[0]=0;
		pq.push({0, 0});
		while(!pq.empty()){
			auto[d, u]=pq.top(); pq.pop();
			if(vis[u]) continue;
			vis[u]=true;
			cout<<d<<' '<<u<<'\n';
			for(auto &[to, h]:v[u]){
				if(!vis[to] && dist[u]+h<dist[to]){
					dist[to]=dist[u]+h;
					pq.push({dist[to], to});
				}
			}
		}
		cout<<'\n';
		for(auto [x, y]:mp) cout<<x.first<<' '<<x.second<<' '<<y<<'\n';
		cout<<'\n';
		// for(auto [x, y]:mp){
		// 	cout<<x.first<<' '<<x.second<<" : ";
		// 	for(auto [node, val]:v[y]) cout<<node<<' ';
		// 	cout<<'\n';
		// }
		// if(dist[1]==INF) cout<<"NO ESCAPE";
		// else cout<<dist[1];
		// cout<<'\n';
	}
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4548 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4548 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4696 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 3 ms 4912 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4548 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4696 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 3 ms 4912 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 332 ms 58268 KB Output is correct
17 Correct 62 ms 20304 KB Output is correct
18 Correct 83 ms 21076 KB Output is correct
19 Correct 410 ms 66712 KB Output is correct
20 Correct 223 ms 47808 KB Output is correct
21 Correct 29 ms 10584 KB Output is correct
22 Incorrect 270 ms 47704 KB Output isn't correct
23 Halted 0 ms 0 KB -