# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017818 |
2024-07-09T10:25:10 Z |
isaachew |
Spy 3 (JOI24_spy3) |
C++17 |
|
109 ms |
6228 KB |
#include "Aoi.h"
#include <bits/stdc++.h>
/*
Send the "shortest path tree of targets" along with which edges are used
*/
namespace {
std::vector<int> parents,parentedges;
std::vector<std::vector<int>> children;
std::vector<std::vector<std::pair<int,int>>> edges;
std::vector<int> targets;
std::vector<int> missinginds;
std::vector<int> reaches;
std::vector<int> ereaches;
int dfs(int cur){
int dpset=0;
for(int i=0;i<targets.size();i++){
if(targets[i]==cur){
dpset|=(1<<i);
reaches.push_back(dpset);
}
}
for(int i:children[cur]){
int oset=dfs(i);
if(oset!=0&&dpset!=0){
reaches.push_back(oset|dpset);
}
dpset|=oset;
}
if(cur){
int eind=missinginds[parentedges[cur]];
if(eind>=0){
ereaches[eind]=dpset;
}
}
return dpset;
}
}
std::string aoi(int N, int M, int Q, int K, std::vector<int> A,
std::vector<int> B, std::vector<long long> C,
std::vector<int> T, std::vector<int> X) {
targets=T;
missinginds.resize(M,-1);
for(int i=0;i<K;i++)missinginds[X[i]]=i;
parents.resize(N);
parentedges.resize(N);
children.resize(N);
edges.resize(N);
ereaches.resize(M);
for(int i=0;i<M;i++){
edges[A[i]].push_back({B[i],i});
edges[B[i]].push_back({A[i],i});
}
std::vector<long long> dists(N,1e18);
std::priority_queue<std::pair<long long,std::pair<int,int>>> dijkstra;
dijkstra.push({0,{-1,0}});//(-dist, (edgenum,index))
while(!dijkstra.empty()){
std::pair<long long,std::pair<int,int>> cur=dijkstra.top();
dijkstra.pop();
cur.first=-cur.first;
int edgenum=cur.second.first;
int curnode=cur.second.second;
if(dists[curnode]<=cur.first)continue;
dists[curnode]=cur.first;
if(curnode){
parents[curnode]=A[edgenum]^B[edgenum]^curnode;
parentedges[curnode]=edgenum;
children[parents[curnode]].push_back(curnode);
}
for(std::pair<int,int> i:edges[curnode]){
dijkstra.push({-(cur.first+C[i.second]),{i.second,i.first}});
}
}
dfs(0);
std::string s(1600, '0');
std::vector<int> stk;
std::vector<int> nreaches;
int ind=0;
for(int i:reaches){
if(i==0)continue;
if(i==(i&-i)){
stk.push_back(i);
nreaches.push_back(i);
s[ind++]='0';
for(int j=0;j<4;j++){
int cbit=__builtin_ctz(i);
s[ind++]=((cbit>>j)&1)|'0';
}
}else{
while(stk.back()!=i){
int last=stk.back();
stk.pop_back();
stk.back()|=last;
nreaches.push_back(stk.back());
s[ind++]='1';
}
}
}
for(int i=0;i<K;i++){
int creach=31;
for(int j=0;j<nreaches.size();j++){
if(ereaches[i]==nreaches[j]){
creach=j;
break;
}
}
for(int j=0;j<5;j++){
s[ind++]=((creach>>j)&1)|'0';
}
}
return s;
}
#include "Bitaro.h"
#include <bits/stdc++.h>
namespace {
} // namespace
void bitaro(int N, int M, int Q, int K, std::vector<int> A, std::vector<int> B,
std::vector<long long> C, std::vector<int> T, std::vector<int> X,
std::string s) {
std::vector<std::vector<std::pair<int,int>>> edges(N);
std::vector<int> stk,rch,missinginds(M);
std::vector<int> mreach(M,2*Q-2);
for(int i=0;i<K;i++){
missinginds[X[i]]=i;
}
int ind=0;
for(int i=0;i<Q*2-1;i++){
if(s[ind++]=='0'){
int num=0;
for(int j=0;j<4;j++){
num+=(1<<j)*(s[ind++]=='1');
}
stk.push_back(1<<num);
rch.push_back(stk.back());
}else{
int comb=stk.back()+stk[stk.size()-2];
stk.pop_back();stk.back()=comb;
rch.push_back(comb);
}
}
rch.resize(32);
for(int i=0;i<K;i++){
int num=0;
for(int j=0;j<5;j++){
num+=(1<<j)*(s[ind++]=='1');
}
mreach[X[i]]=num;
}
for(int i=0;i<M;i++){
edges[A[i]].push_back({B[i],i});
edges[B[i]].push_back({A[i],i});
}
for(int qn=0;qn<Q;qn++){
std::vector<long long> dists(N,1e18);
std::priority_queue<std::pair<long long,std::pair<int,int>>> dijkstra;
std::vector<int> parents(N),parentedges(N);
dijkstra.push({0,{-1,0}});//(-dist, (edgenum,index))
while(!dijkstra.empty()){
std::pair<long long,std::pair<int,int>> cur=dijkstra.top();
dijkstra.pop();
cur.first=-cur.first;
int edgenum=cur.second.first;
int curnode=cur.second.second;
if(dists[curnode]<=cur.first)continue;
dists[curnode]=cur.first;
if(curnode){
parents[curnode]=A[edgenum]^B[edgenum]^curnode;
parentedges[curnode]=edgenum;
}
for(std::pair<int,int> i:edges[curnode]){
if(missinginds[i.second]>=0){
if(((rch[mreach[i.second]]>>qn)&1)==0)continue;
}
dijkstra.push({-(cur.first+std::max(0ll,C[i.second])),{i.second,i.first}});
}
}
std::vector<int> result;
int loc=T[qn];
while(loc!=0){
result.push_back(parentedges[loc]);
loc=parents[loc];
}
std::reverse(result.begin(),result.end());
answer(result);
}
}
Compilation message
Aoi.cpp: In function 'int {anonymous}::dfs(int)':
Aoi.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<targets.size();i++){
| ~^~~~~~~~~~~~~~~
Aoi.cpp: In function 'std::string aoi(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<long long int>, std::vector<int>, std::vector<int>)':
Aoi.cpp:103:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int j=0;j<nreaches.size();j++){
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
93 ms |
6228 KB |
Partially correct |
2 |
Partially correct |
0 ms |
776 KB |
Partially correct |
3 |
Partially correct |
64 ms |
4804 KB |
Partially correct |
4 |
Partially correct |
39 ms |
4808 KB |
Partially correct |
5 |
Partially correct |
81 ms |
4616 KB |
Partially correct |
6 |
Partially correct |
66 ms |
4536 KB |
Partially correct |
7 |
Partially correct |
74 ms |
4784 KB |
Partially correct |
8 |
Partially correct |
59 ms |
4536 KB |
Partially correct |
9 |
Partially correct |
35 ms |
4912 KB |
Partially correct |
10 |
Partially correct |
24 ms |
4788 KB |
Partially correct |
11 |
Partially correct |
73 ms |
4532 KB |
Partially correct |
12 |
Partially correct |
60 ms |
4548 KB |
Partially correct |
13 |
Partially correct |
66 ms |
4580 KB |
Partially correct |
14 |
Partially correct |
78 ms |
4580 KB |
Partially correct |
15 |
Partially correct |
52 ms |
4792 KB |
Partially correct |
16 |
Partially correct |
17 ms |
4788 KB |
Partially correct |
17 |
Partially correct |
55 ms |
5744 KB |
Partially correct |
18 |
Partially correct |
56 ms |
5720 KB |
Partially correct |
19 |
Partially correct |
96 ms |
6208 KB |
Partially correct |
20 |
Partially correct |
71 ms |
5840 KB |
Partially correct |
21 |
Partially correct |
96 ms |
5688 KB |
Partially correct |
22 |
Partially correct |
89 ms |
5756 KB |
Partially correct |
23 |
Partially correct |
61 ms |
5992 KB |
Partially correct |
24 |
Partially correct |
89 ms |
5760 KB |
Partially correct |
25 |
Partially correct |
72 ms |
5508 KB |
Partially correct |
26 |
Partially correct |
72 ms |
5592 KB |
Partially correct |
27 |
Partially correct |
0 ms |
776 KB |
Partially correct |
28 |
Partially correct |
73 ms |
4632 KB |
Partially correct |
29 |
Partially correct |
19 ms |
4116 KB |
Partially correct |
30 |
Partially correct |
65 ms |
5000 KB |
Partially correct |
31 |
Partially correct |
35 ms |
4888 KB |
Partially correct |
32 |
Partially correct |
76 ms |
4880 KB |
Partially correct |
33 |
Partially correct |
75 ms |
4632 KB |
Partially correct |
34 |
Partially correct |
66 ms |
5064 KB |
Partially correct |
35 |
Partially correct |
66 ms |
5060 KB |
Partially correct |
36 |
Partially correct |
58 ms |
5004 KB |
Partially correct |
37 |
Partially correct |
10 ms |
3868 KB |
Partially correct |
38 |
Partially correct |
20 ms |
4632 KB |
Partially correct |
39 |
Partially correct |
26 ms |
4660 KB |
Partially correct |
40 |
Partially correct |
9 ms |
4028 KB |
Partially correct |
41 |
Partially correct |
108 ms |
5780 KB |
Partially correct |
42 |
Partially correct |
57 ms |
6048 KB |
Partially correct |
43 |
Partially correct |
98 ms |
6148 KB |
Partially correct |
44 |
Partially correct |
26 ms |
5804 KB |
Partially correct |
45 |
Partially correct |
10 ms |
3320 KB |
Partially correct |
46 |
Partially correct |
14 ms |
4100 KB |
Partially correct |
47 |
Partially correct |
16 ms |
4124 KB |
Partially correct |
48 |
Partially correct |
0 ms |
776 KB |
Partially correct |
49 |
Partially correct |
0 ms |
776 KB |
Partially correct |
50 |
Partially correct |
60 ms |
6116 KB |
Partially correct |
51 |
Partially correct |
4 ms |
1284 KB |
Partially correct |
52 |
Partially correct |
0 ms |
776 KB |
Partially correct |
53 |
Partially correct |
94 ms |
6132 KB |
Partially correct |
54 |
Partially correct |
57 ms |
4060 KB |
Partially correct |
55 |
Partially correct |
62 ms |
4168 KB |
Partially correct |
56 |
Partially correct |
65 ms |
5860 KB |
Partially correct |
57 |
Partially correct |
97 ms |
5712 KB |
Partially correct |
58 |
Partially correct |
73 ms |
4780 KB |
Partially correct |
59 |
Partially correct |
108 ms |
5824 KB |
Partially correct |
60 |
Partially correct |
102 ms |
6096 KB |
Partially correct |
61 |
Partially correct |
98 ms |
5884 KB |
Partially correct |
62 |
Partially correct |
92 ms |
5280 KB |
Partially correct |
63 |
Partially correct |
109 ms |
6040 KB |
Partially correct |
64 |
Partially correct |
19 ms |
5112 KB |
Partially correct |
65 |
Partially correct |
44 ms |
4260 KB |
Partially correct |
66 |
Partially correct |
48 ms |
6036 KB |
Partially correct |
67 |
Partially correct |
46 ms |
4240 KB |
Partially correct |
68 |
Partially correct |
50 ms |
6172 KB |
Partially correct |
69 |
Partially correct |
0 ms |
776 KB |
Partially correct |
70 |
Partially correct |
1 ms |
800 KB |
Partially correct |
71 |
Partially correct |
0 ms |
776 KB |
Partially correct |
72 |
Partially correct |
16 ms |
3060 KB |
Partially correct |
73 |
Partially correct |
39 ms |
3600 KB |
Partially correct |
74 |
Partially correct |
40 ms |
3600 KB |
Partially correct |
75 |
Partially correct |
12 ms |
3508 KB |
Partially correct |
76 |
Partially correct |
0 ms |
776 KB |
Partially correct |
77 |
Partially correct |
80 ms |
4256 KB |
Partially correct |
78 |
Partially correct |
79 ms |
4024 KB |
Partially correct |
79 |
Partially correct |
71 ms |
4280 KB |
Partially correct |
80 |
Partially correct |
0 ms |
776 KB |
Partially correct |
81 |
Partially correct |
80 ms |
4656 KB |
Partially correct |
82 |
Partially correct |
80 ms |
4612 KB |
Partially correct |
83 |
Partially correct |
71 ms |
4628 KB |
Partially correct |