Submission #1039886

# Submission time Handle Problem Language Result Execution time Memory
1039886 2024-07-31T11:27:25 Z Unforgettablepl Spy 3 (JOI24_spy3) C++17
100 / 100
52 ms 5092 KB
#include "Aoi.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
}

string  aoi(int N, int M, int Q, int K, vector<int> A,
			vector<int> B, vector<long long> C,
			vector<int> T, vector<int> X) {
	vector<int> forgotten(M+1,K);
	for(int i=0;i<K;i++)forgotten[X[i]]=i;
	vector<pair<int,int>> paredge(N);
	vector<vector<pair<int,int>>> adj(N);
	for(int i=0;i<M;i++){
		adj[A[i]].emplace_back(B[i],i);
		adj[B[i]].emplace_back(A[i],i);
	}
	priority_queue<tuple<long long,int,int>> pq;
	vector<bool> visited(N);
	pq.emplace(0,0,M);
	while(!pq.empty()){
		auto [dist,curr,pedge] = pq.top();pq.pop();dist=-dist;
		if(visited[curr])continue;
		visited[curr]=true;
		if(pedge==M){}
		else if(A[pedge]==curr)paredge[curr]={B[pedge],forgotten[pedge]};
		else paredge[curr]={A[pedge],forgotten[pedge]};
		for(auto[v,idx]:adj[curr])if(!visited[v]){
			pq.emplace(-dist-C[idx],v,idx);
		}
	}
	vector<int> firstuseby(300,Q);
	vector<int> lastedgeused(Q,K);
	string res;
	for(int i=0;i<Q;i++){
		int curr = T[i];
		while(curr){
			if(paredge[curr].second!=K){
				if(firstuseby[paredge[curr].second]==Q)firstuseby[paredge[curr].second]=i;
				else {lastedgeused[i]=paredge[curr].second;break;}
			}
			curr = paredge[curr].first;
		}
	}
	for(int i=1;i<Q;i++){
		for(int bit=0;bit<9;bit++)if(lastedgeused[i]&(1<<bit))res.insert(res.end(),'1');
								  else res.insert(res.end(),'0');
	}
	for(int i=0;i<K;i+=2){
		int poss = firstuseby[i]*17+firstuseby[i+1];
		for(int bit=0;bit<9;bit++)if(poss&(1<<bit))res.insert(res.end(),'1');
								  else res.insert(res.end(),'0');	
	}
	return res;
}
#include "Bitaro.h"
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;

namespace {

}

void bitaro(int N, int M, int Q, int K, vector<int> A, vector<int> B,
			vector<long long> C, vector<int> T, vector<int> X,
			string s) {
	vector<pair<int,int>> finalparedge(N);
	vector<vector<pair<int,int>>> adj(N);
	vector<int> isForgotten(M,K);
	for(int i=0;i<K;i++)isForgotten[X[i]]=i;
	for(int i=0;i<M;i++){
		adj[A[i]].emplace_back(B[i],i);
		adj[B[i]].emplace_back(A[i],i);
	}
	int ptr = 0;
	auto read = [&](){
		return s[ptr++]=='1';
	};
	vector<int> firstuseby(300);
	vector<int> lastedgeused(Q);
	lastedgeused[0]=K;
	for(int i=1;i<Q;i++){
		for(int bit=0;bit<9;bit++)
			if(read())
				lastedgeused[i]|=(1<<bit);
	}
	for(int i=0;i<K;i+=2){
		int poss = 0;
		for(int bit=0;bit<9;bit++)if(read())poss|=(1<<bit);	
		firstuseby[i]=poss/17;
		firstuseby[i+1]=poss%17;
	}
	for(int sce=0;sce<Q;sce++){
		vector<pair<int,int>> paredge(N);
		vector<bool> included(K);
		if(lastedgeused[sce]!=K){
			included[lastedgeused[sce]]=true;
			int curr = A[X[lastedgeused[sce]]];
			while(curr){
				if(isForgotten[finalparedge[curr].second]!=K)included[isForgotten[finalparedge[curr].second]]=true;
				curr = finalparedge[curr].first;
			}
		}
		for(int i=0;i<K;i++)if(firstuseby[i]==sce)included[i]=true;
		for(int i=0;i<K;i++){
			if(included[i])C[X[i]]=0;
			else C[X[i]]=INF;
		}
		priority_queue<tuple<long long,int,int>> pq;
		vector<bool> visited(N);
		pq.emplace(0,0,M);
		while(!pq.empty()){
			auto [dist,curr,pedge] = pq.top();pq.pop();dist=-dist;
			if(visited[curr])continue;
			visited[curr]=true;
			if(pedge==M){}
			else if(A[pedge]==curr)paredge[curr]={B[pedge],pedge};
			else paredge[curr]={A[pedge],pedge};
			for(auto[v,idx]:adj[curr])if(!visited[v]){
				pq.emplace(-dist-C[idx],v,idx);
			}
		}
		vector<int> ans;
		int curr = T[sce];
		while(curr){
			finalparedge[curr] = paredge[curr];
			ans.emplace_back(paredge[curr].second);
			curr = paredge[curr].first;
		}
		reverse(ans.begin(),ans.end());
		answer(ans);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4852 KB Output is correct
2 Correct 0 ms 776 KB Output is correct
3 Correct 39 ms 4228 KB Output is correct
4 Correct 28 ms 3752 KB Output is correct
5 Correct 42 ms 4112 KB Output is correct
6 Correct 38 ms 4108 KB Output is correct
7 Correct 41 ms 4120 KB Output is correct
8 Correct 43 ms 4096 KB Output is correct
9 Correct 32 ms 3800 KB Output is correct
10 Correct 17 ms 3868 KB Output is correct
11 Correct 41 ms 4108 KB Output is correct
12 Correct 32 ms 4056 KB Output is correct
13 Correct 36 ms 4248 KB Output is correct
14 Correct 38 ms 4012 KB Output is correct
15 Correct 31 ms 4128 KB Output is correct
16 Correct 12 ms 3604 KB Output is correct
17 Correct 34 ms 4068 KB Output is correct
18 Correct 34 ms 4188 KB Output is correct
19 Correct 43 ms 4920 KB Output is correct
20 Correct 34 ms 4816 KB Output is correct
21 Correct 42 ms 4808 KB Output is correct
22 Correct 45 ms 4808 KB Output is correct
23 Correct 28 ms 4824 KB Output is correct
24 Correct 40 ms 4752 KB Output is correct
25 Correct 38 ms 4520 KB Output is correct
26 Correct 39 ms 4396 KB Output is correct
27 Correct 0 ms 784 KB Output is correct
28 Correct 42 ms 3904 KB Output is correct
29 Correct 21 ms 3236 KB Output is correct
30 Correct 37 ms 4052 KB Output is correct
31 Correct 27 ms 4160 KB Output is correct
32 Correct 41 ms 4376 KB Output is correct
33 Correct 37 ms 4120 KB Output is correct
34 Correct 41 ms 4208 KB Output is correct
35 Correct 45 ms 4020 KB Output is correct
36 Correct 45 ms 4176 KB Output is correct
37 Correct 10 ms 2584 KB Output is correct
38 Correct 19 ms 3300 KB Output is correct
39 Correct 24 ms 3344 KB Output is correct
40 Correct 6 ms 2832 KB Output is correct
41 Correct 52 ms 4864 KB Output is correct
42 Correct 31 ms 5000 KB Output is correct
43 Correct 46 ms 5092 KB Output is correct
44 Correct 14 ms 4864 KB Output is correct
45 Correct 9 ms 2588 KB Output is correct
46 Correct 16 ms 3028 KB Output is correct
47 Correct 19 ms 3076 KB Output is correct
48 Correct 0 ms 776 KB Output is correct
49 Correct 1 ms 784 KB Output is correct
50 Correct 25 ms 4740 KB Output is correct
51 Correct 2 ms 780 KB Output is correct
52 Correct 0 ms 776 KB Output is correct
53 Correct 41 ms 4828 KB Output is correct
54 Correct 24 ms 3232 KB Output is correct
55 Correct 32 ms 3452 KB Output is correct
56 Correct 33 ms 4904 KB Output is correct
57 Correct 46 ms 4936 KB Output is correct
58 Correct 35 ms 4012 KB Output is correct
59 Correct 51 ms 5092 KB Output is correct
60 Correct 48 ms 5048 KB Output is correct
61 Correct 47 ms 5008 KB Output is correct
62 Correct 45 ms 4532 KB Output is correct
63 Correct 47 ms 5068 KB Output is correct
64 Correct 15 ms 4272 KB Output is correct
65 Correct 20 ms 3976 KB Output is correct
66 Correct 23 ms 5036 KB Output is correct
67 Correct 21 ms 3876 KB Output is correct
68 Correct 24 ms 4972 KB Output is correct
69 Correct 0 ms 784 KB Output is correct
70 Correct 0 ms 776 KB Output is correct
71 Correct 1 ms 776 KB Output is correct
72 Correct 11 ms 2584 KB Output is correct
73 Correct 22 ms 3096 KB Output is correct
74 Correct 22 ms 3096 KB Output is correct
75 Correct 8 ms 2836 KB Output is correct
76 Correct 0 ms 784 KB Output is correct
77 Correct 40 ms 3992 KB Output is correct
78 Correct 41 ms 4004 KB Output is correct
79 Correct 41 ms 3764 KB Output is correct
80 Correct 0 ms 776 KB Output is correct
81 Correct 40 ms 4108 KB Output is correct
82 Correct 45 ms 4172 KB Output is correct
83 Correct 37 ms 4112 KB Output is correct