Submission #1036604

# Submission time Handle Problem Language Result Execution time Memory
1036604 2024-07-27T14:44:30 Z Unforgettablepl Board Game (JOI24_boardgame) C++17
17 / 100
50 ms 6868 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 1e13;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,k;
	cin >> n >> m >> k;
	vector<vector<int>> adj(n+1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}
	vector<bool> isStop(n+1);
	bool works = false;
	for(int i=1;i<=n;i++){
		char a;cin>>a;
		if(a=='1'){works=isStop[i]=true;}
	}
	vector<int> starts(k+1);
	for(int i=1;i<=k;i++)cin>>starts[i];
	vector<int> minmoves(n+1,INF);
	minmoves[0]=0;
	if(works){
		// calculate minmoves
		vector<int> nearest_single(n+1,-1);
		priority_queue<pair<int,int>> pq;
		for(int i=1;i<=n;i++)if(isStop[i])for(int&x:adj[i])pq.emplace(-1,x);
		vector<bool> visited(n+1);
		while(!pq.empty()){
			auto [dist,idx] = pq.top();pq.pop();dist=-dist;
			if(visited[idx])continue;
			visited[idx]=true;
			nearest_single[idx]=dist;
			for(int&i:adj[idx])if(!visited[i])pq.emplace(-dist-1,i);
		}
		vector<int> nearest_double(n+1,-1);
		for(int i=1;i<=n;i++)if(isStop[i]){
			for(int&x:adj[i]){
				if(isStop[x]){
					pq.emplace(0,i);
					break;
				}
			}
		}
		visited = vector<bool>(n+1);
		while(!pq.empty()){
			auto [dist,idx] = pq.top();pq.pop();dist=-dist;
			if(visited[idx])continue;
			visited[idx]=true;
			nearest_double[idx]=dist;
			if(!isStop[idx])nearest_double[idx]--;
			for(int&i:adj[idx])if(!visited[i]){
				if(!isStop[i])pq.emplace(-dist-1,i);
				else pq.emplace(-dist,i);
			}
		}
		vector<int> slopeedit(n+1);
		int base = 0;
		auto process = [&](int x){
			base+=nearest_single[x];
			slopeedit[1]+=2;
			if(nearest_double[1]!=-1 and nearest_double[x]-nearest_single[x]+2<=n)slopeedit[nearest_double[x]-nearest_single[x]+2]--;
		};
		for(int i=2;i<=k;i++){
			process(starts[i]);
		}
		int currslope = 0;
		for(int i=1;i<=n;i++){
			base+=currslope;
			minmoves[i]=base;
			currslope+=slopeedit[i];
		}
		for(int i=n;i;i--)minmoves[i]-=minmoves[i-1];
	}
	vector<int> currbest(n+1,INF);
	vector<int> ans(n+1,INF);
	vector<bool> visited(n+1);
	priority_queue<tuple<int,int,int>> pq;
	pq.emplace(0,0,starts[1]);
	while(!pq.empty()){
		auto [stops,dist,idx] = pq.top();pq.pop();dist=-dist;stops=-stops;
		if(visited[idx])continue;
		if(isStop[idx])currbest[idx] = dist-minmoves[stops];
		else currbest[idx] = dist;
		visited[idx] = true;
		for(int&i:adj[idx]){
			if(isStop[i]){
				if(dist+1+minmoves[stops+1]<currbest[i]){
					currbest[i] = dist+1+minmoves[stops+1];
					pq.emplace(-stops-1,-dist-1-minmoves[stops+1],i);
					visited[i]=false;
				} 
				ans[i]=min(ans[i],dist+1);
			} else {
				if(dist+1<currbest[i]){
					currbest[i] = dist+1;
					pq.emplace(-stops,-dist-1,i);
					visited[i]=false;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)cout<<min(currbest[i],ans[i])<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 11 ms 3676 KB Output is correct
3 Correct 19 ms 6200 KB Output is correct
4 Correct 16 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 16 ms 3932 KB Output is correct
3 Correct 25 ms 5648 KB Output is correct
4 Correct 19 ms 5428 KB Output is correct
5 Correct 34 ms 6252 KB Output is correct
6 Correct 27 ms 5456 KB Output is correct
7 Correct 22 ms 4956 KB Output is correct
8 Correct 19 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 644 KB Output is correct
2 Correct 16 ms 3940 KB Output is correct
3 Correct 25 ms 5488 KB Output is correct
4 Correct 20 ms 5572 KB Output is correct
5 Correct 23 ms 6076 KB Output is correct
6 Correct 24 ms 5464 KB Output is correct
7 Correct 25 ms 5608 KB Output is correct
8 Correct 23 ms 6084 KB Output is correct
9 Correct 17 ms 3300 KB Output is correct
10 Correct 17 ms 3288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 572 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 644 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Incorrect 2 ms 604 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 5460 KB Output is correct
2 Correct 37 ms 6096 KB Output is correct
3 Correct 24 ms 5460 KB Output is correct
4 Incorrect 50 ms 6868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 5460 KB Output is correct
2 Correct 37 ms 6096 KB Output is correct
3 Correct 24 ms 5460 KB Output is correct
4 Incorrect 50 ms 6868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 572 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 644 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Incorrect 2 ms 604 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 11 ms 3676 KB Output is correct
3 Correct 19 ms 6200 KB Output is correct
4 Correct 16 ms 5464 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 16 ms 3932 KB Output is correct
7 Correct 25 ms 5648 KB Output is correct
8 Correct 19 ms 5428 KB Output is correct
9 Correct 34 ms 6252 KB Output is correct
10 Correct 27 ms 5456 KB Output is correct
11 Correct 22 ms 4956 KB Output is correct
12 Correct 19 ms 5212 KB Output is correct
13 Correct 1 ms 644 KB Output is correct
14 Correct 16 ms 3940 KB Output is correct
15 Correct 25 ms 5488 KB Output is correct
16 Correct 20 ms 5572 KB Output is correct
17 Correct 23 ms 6076 KB Output is correct
18 Correct 24 ms 5464 KB Output is correct
19 Correct 25 ms 5608 KB Output is correct
20 Correct 23 ms 6084 KB Output is correct
21 Correct 17 ms 3300 KB Output is correct
22 Correct 17 ms 3288 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 572 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 644 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Incorrect 2 ms 604 KB Output isn't correct
32 Halted 0 ms 0 KB -