QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217692 | #5109. Spider Walk | ucup-team1004# | WA | 481ms | 132172kb | C++14 | 2.1kb | 2023-10-17 10:17:16 | 2023-10-17 10:17:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=2e5+10,M=5e5+10,V=N+M*2,INF=1e9;
int n,m,k,s,d[M],t[M],dis[V];
vector<int>p[N],id[N];
vector<pair<int,int> >to[V];
void add(int u,int v,int w){
// if(!w)debug(u,v,w);
to[u].push_back({v,w});
}
#define v e.first
#define w e.second
void dij(int s,int *d){
deque<int>q;
fill(d+1,d+1+k,INF),q.push_back(s),d[s]=0;
for(int u;!q.empty();){
u=q.front(),q.pop_front();
for(auto e:to[u]){
if(d[v]>d[u]+w){
d[v]=d[u]+w;
if(w)q.push_back(v);
else q.push_front(v);
}
}
}
}
#undef v
#undef w
int main(){
scanf("%d%d%d",&n,&m,&s);
for(int i=1;i<=m;i++){
scanf("%d%d",&d[i],&t[i]);
p[t[i]].push_back(d[i]);
p[t[i]%n+1].push_back(d[i]);
}
for(int i=1;i<=n;i++){
sort(p[i].begin(),p[i].end());
p[i].push_back(INF);
id[i].assign(p[i].size(),0);
iota(id[i].begin(),id[i].end(),k+1);
k+=id[i].size();
}
// debug(s);
s=id[s].back();
for(int i=1;i<=m;i++){
int u=t[i],v=t[i]%n+1;
// debug(p[u],p[v],d[i]);
int x=lower_bound(p[u].begin(),p[u].end(),d[i])-p[u].begin();
int y=lower_bound(p[v].begin(),p[v].end(),d[i])-p[v].begin();
add(id[u][x+1],id[v][y],0),add(id[v][y+1],id[u][x],0);
}
// debug(id[3],p[3]);
// debug(id[4],p[4]);
// debug(id[5],p[5]);
// debug(id[6],p[6]);
for(int u=1;u<=n;u++){
int v=u%n+1;
int l1=p[u].size(),l2=p[v].size();
for(int i=0,j=0;i<l1&&j<l2;){
if(p[u][i]>=p[v][j])add(id[u][i],id[v][j],1);
if(p[v][j]>=p[u][i])add(id[v][j],id[u][i],1);
if(p[u][i]<p[v][j])i++;
else j++;
}
}
dij(s,dis);
for(int i=1;i<=n;i++)printf("%d\n",dis[id[i][0]]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 201ms
memory: 128068kb
input:
200000 500000 116205 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 200000 lines
Test #2:
score: -100
Wrong Answer
time: 481ms
memory: 132172kb
input:
200000 500000 200000 1 148896 2 178903 3 36800 4 98361 5 79634 6 29266 7 51632 8 166082 9 66246 10 145043 11 41644 12 81858 13 87530 14 199625 15 127160 16 49786 17 181673 18 48403 19 30274 20 101455 21 105100 22 52149 23 22810 24 79308 25 191579 26 96365 27 154697 28 45255 29 64965 30 192604 31 330...
output:
1 0 1 4 5 5 6 6 9 10 10 11 12 11 15 16 16 16 16 15 21 21 20 21 22 23 23 22 24 25 24 25 25 26 33 34 34 36 37 37 36 37 38 41 40 41 42 43 43 48 49 50 51 51 54 53 54 55 56 56 60 60 61 61 64 65 65 64 65 66 65 72 73 72 74 75 75 76 76 76 77 78 78 82 82 84 85 86 87 88 88 89 90 91 92 91 95 96 97 98 99 99 99 ...
result:
wrong answer 4th lines differ - expected: '1', found: '4'