# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1012842 |
2024-07-02T16:58:04 Z |
huutuan |
Spy 3 (JOI24_spy3) |
C++17 |
|
53 ms |
7040 KB |
#include "Aoi.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace Aoi{
const int N=1e4+10, M=2e4+10;
int n, m;
pair<pair<int, int>, int> edge[M];
vector<int> g[N];
int tr[N], f[N];
int t[M], p[N];
void dijkstra(){
memset(f, 0x3f, sizeof f);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.emplace(f[0]=0, 0);
while (pq.size()){
int u=pq.top().second, d=pq.top().first;
pq.pop();
if (f[u]!=d) continue;
for (int i:g[u]){
int v=edge[i].first.first^edge[i].first.second^u;
int w=edge[i].second;
if (f[v]>d+w) pq.emplace(f[v]=d+w, v), tr[v]=i;
}
}
}
bool del[M];
void trace(int u, vector<int> &ans){
if (u==0) return;
ans.push_back(tr[u]);
return trace(edge[tr[u]].first.first^edge[tr[u]].first.second^u, ans);
}
string solve(int32_t _N, int32_t _M, int32_t Q, int32_t K, vector<int32_t> A,
vector<int32_t> B, vector<long long> C,
vector<int32_t> T, vector<int32_t> X){
n=_N, m=_M;
for (int i=0; i<m; ++i){
edge[i]={{A[i], B[i]}, C[i]};
g[A[i]].push_back(i);
g[B[i]].push_back(i);
}
for (int i:X) del[i]=1, t[i]=Q;
dijkstra();
string ans;
for (int i=0; i<Q; ++i){
p[i]=K;
vector<int> path;
trace(T[i], path);
for (int j:path){
if (del[j]){
if (t[j]<i && p[i]==K){
p[i]=find(X.begin(), X.end(), j)-X.begin();
}
t[j]=min(t[j], i);
}
}
}
for (int i=0; i<K; i+=11){
int val=0;
for (int j=i, pw=1; j<K && j<i+11; ++j, pw*=17){
val+=t[X[j]]*pw;
}
ans+=bitset<45>(val).to_string();
}
for (int i=0; i<Q; ++i){
ans+=bitset<9>(p[i]).to_string();
}
#ifdef sus
ofstream out("spy3.out");
for (int i:T) out << f[i] << ' ';
out << '\n';
out.close();
#endif
return ans;
}
}
string aoi(int32_t N, int32_t M, int32_t Q, int32_t K, vector<int32_t> A,
vector<int32_t> B, vector<long long> C,
vector<int32_t> T, vector<int32_t> X) {
return Aoi::solve(N, M, Q, K, A, B, C, T, X);
}
#include "Bitaro.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace Bitaro{
const int N=1e4+10, M=2e4+10, inf=1e18;
int n, m, q, k;
pair<pair<int, int>, int> edge[M];
vector<int> g[N];
int tr[N], f[N];
int t[M], p[N];
void trace(int u, vector<int32_t> &ans){
if (u==0) return;
ans.push_back(tr[u]);
return trace(edge[tr[u]].first.first^edge[tr[u]].first.second^u, ans);
}
void dijkstra(){
memset(f, 0x3f, sizeof f);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.emplace(f[0]=0, 0);
while (pq.size()){
int u=pq.top().second, d=pq.top().first;
pq.pop();
if (f[u]!=d) continue;
for (int i:g[u]){
int v=edge[i].first.first^edge[i].first.second^u;
int w=edge[i].second;
if (f[v]>d+w) pq.emplace(f[v]=d+w, v), tr[v]=i;
}
}
}
int par[M];
bool del[M];
void solve(int32_t _N, int32_t _M, int32_t Q, int32_t K, vector<int32_t> A, vector<int32_t> B,
vector<long long> C, vector<int32_t> T, vector<int32_t> X,
string s){
n=_N, m=_M, q=Q, k=K;
for (int i=0; i<m; ++i){
edge[i]={{A[i], B[i]}, C[i]};
g[A[i]].push_back(i);
g[B[i]].push_back(i);
}
int cur=0;
for (int i=0; i<K; i+=11){
int val=bitset<45>(s.substr(cur, 45)).to_ullong(); cur+=45;
for (int j=i; j<K && j<i+11; ++j) t[X[j]]=val%17, val/=17;
}
for (int i:X) del[i]=1;
for (int i=0; i<m; ++i) par[i]=m;
for (int i=0; i<Q; ++i) p[i]=bitset<9>(s.substr(cur, 9)).to_ullong(), cur+=9;
for (int i=0; i<Q; ++i){
vector<int> v;
for (int j:X) if (t[j]==i) v.push_back(j);
int id=p[i]==K?m:X[p[i]];
while (id!=m){
v.push_back(id);
id=par[id];
}
for (int j:X) edge[j].second=inf;
for (int j:v) edge[j].second=0;
dijkstra();
vector<int32_t> path;
trace(T[i], path); reverse(path.begin(), path.end());
answer(path);
int lst=p[i]==K?m:X[p[i]];
for (int j:path) if (del[j] && t[j]==i){
par[j]=lst;
lst=j;
}
}
}
}
void bitaro(int32_t N, int32_t M, int32_t Q, int32_t K, vector<int32_t> A, vector<int32_t> B,
vector<long long> C, vector<int32_t> T, vector<int32_t> X,
string s) {
Bitaro::solve(N, M, Q, K, A, B, C, T, X, s);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5556 KB |
Output is correct |
2 |
Correct |
1 ms |
1288 KB |
Output is correct |
3 |
Correct |
30 ms |
6152 KB |
Output is correct |
4 |
Correct |
31 ms |
5660 KB |
Output is correct |
5 |
Correct |
38 ms |
6168 KB |
Output is correct |
6 |
Correct |
34 ms |
6076 KB |
Output is correct |
7 |
Correct |
31 ms |
6144 KB |
Output is correct |
8 |
Correct |
30 ms |
6136 KB |
Output is correct |
9 |
Correct |
28 ms |
5648 KB |
Output is correct |
10 |
Correct |
16 ms |
5664 KB |
Output is correct |
11 |
Correct |
32 ms |
6096 KB |
Output is correct |
12 |
Correct |
41 ms |
6080 KB |
Output is correct |
13 |
Correct |
34 ms |
6072 KB |
Output is correct |
14 |
Correct |
28 ms |
6068 KB |
Output is correct |
15 |
Correct |
33 ms |
5612 KB |
Output is correct |
16 |
Correct |
15 ms |
5652 KB |
Output is correct |
17 |
Correct |
44 ms |
5880 KB |
Output is correct |
18 |
Correct |
47 ms |
5828 KB |
Output is correct |
19 |
Correct |
39 ms |
6756 KB |
Output is correct |
20 |
Correct |
29 ms |
6724 KB |
Output is correct |
21 |
Correct |
36 ms |
6724 KB |
Output is correct |
22 |
Correct |
50 ms |
6744 KB |
Output is correct |
23 |
Correct |
37 ms |
6736 KB |
Output is correct |
24 |
Correct |
47 ms |
6768 KB |
Output is correct |
25 |
Correct |
44 ms |
5752 KB |
Output is correct |
26 |
Correct |
41 ms |
5816 KB |
Output is correct |
27 |
Correct |
1 ms |
1300 KB |
Output is correct |
28 |
Correct |
31 ms |
6068 KB |
Output is correct |
29 |
Correct |
18 ms |
4624 KB |
Output is correct |
30 |
Correct |
35 ms |
6176 KB |
Output is correct |
31 |
Correct |
24 ms |
6168 KB |
Output is correct |
32 |
Correct |
39 ms |
6200 KB |
Output is correct |
33 |
Correct |
37 ms |
5972 KB |
Output is correct |
34 |
Correct |
35 ms |
6272 KB |
Output is correct |
35 |
Correct |
28 ms |
6304 KB |
Output is correct |
36 |
Correct |
33 ms |
6256 KB |
Output is correct |
37 |
Correct |
9 ms |
3604 KB |
Output is correct |
38 |
Correct |
20 ms |
4700 KB |
Output is correct |
39 |
Correct |
20 ms |
4636 KB |
Output is correct |
40 |
Correct |
8 ms |
3860 KB |
Output is correct |
41 |
Correct |
47 ms |
6504 KB |
Output is correct |
42 |
Correct |
31 ms |
6584 KB |
Output is correct |
43 |
Correct |
53 ms |
6948 KB |
Output is correct |
44 |
Correct |
16 ms |
6584 KB |
Output is correct |
45 |
Correct |
9 ms |
3524 KB |
Output is correct |
46 |
Correct |
13 ms |
4116 KB |
Output is correct |
47 |
Correct |
17 ms |
4176 KB |
Output is correct |
48 |
Correct |
0 ms |
1300 KB |
Output is correct |
49 |
Correct |
0 ms |
1300 KB |
Output is correct |
50 |
Correct |
13 ms |
5464 KB |
Output is correct |
51 |
Correct |
2 ms |
1804 KB |
Output is correct |
52 |
Correct |
1 ms |
1300 KB |
Output is correct |
53 |
Correct |
13 ms |
5664 KB |
Output is correct |
54 |
Correct |
9 ms |
4368 KB |
Output is correct |
55 |
Correct |
25 ms |
4880 KB |
Output is correct |
56 |
Correct |
22 ms |
6160 KB |
Output is correct |
57 |
Correct |
36 ms |
6604 KB |
Output is correct |
58 |
Correct |
27 ms |
5132 KB |
Output is correct |
59 |
Correct |
40 ms |
6636 KB |
Output is correct |
60 |
Correct |
33 ms |
6656 KB |
Output is correct |
61 |
Correct |
44 ms |
6676 KB |
Output is correct |
62 |
Correct |
40 ms |
6072 KB |
Output is correct |
63 |
Correct |
44 ms |
6604 KB |
Output is correct |
64 |
Correct |
14 ms |
5900 KB |
Output is correct |
65 |
Correct |
24 ms |
5032 KB |
Output is correct |
66 |
Correct |
20 ms |
7040 KB |
Output is correct |
67 |
Correct |
24 ms |
5032 KB |
Output is correct |
68 |
Correct |
21 ms |
7036 KB |
Output is correct |
69 |
Correct |
0 ms |
1288 KB |
Output is correct |
70 |
Correct |
0 ms |
1292 KB |
Output is correct |
71 |
Correct |
2 ms |
1292 KB |
Output is correct |
72 |
Correct |
12 ms |
3348 KB |
Output is correct |
73 |
Correct |
22 ms |
4084 KB |
Output is correct |
74 |
Correct |
23 ms |
4084 KB |
Output is correct |
75 |
Correct |
10 ms |
4112 KB |
Output is correct |
76 |
Correct |
1 ms |
1292 KB |
Output is correct |
77 |
Correct |
28 ms |
5748 KB |
Output is correct |
78 |
Correct |
26 ms |
5992 KB |
Output is correct |
79 |
Correct |
32 ms |
6068 KB |
Output is correct |
80 |
Correct |
0 ms |
1292 KB |
Output is correct |
81 |
Correct |
39 ms |
6076 KB |
Output is correct |
82 |
Correct |
31 ms |
6068 KB |
Output is correct |
83 |
Correct |
36 ms |
6164 KB |
Output is correct |