QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217691 | #5109. Spider Walk | qzez | WA | 548ms | 150112kb | C++14 | 2.1kb | 2023-10-17 10:15:27 | 2023-10-17 10:15:27 |
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;){
add(id[u][i],id[v][j],1),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: 233ms
memory: 150112kb
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: 548ms
memory: 148328kb
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 1 2 2 3 3 4 5 5 6 6 6 7 8 8 9 9 8 9 10 10 11 12 12 12 11 12 13 13 14 14 15 16 17 17 18 19 19 18 19 19 20 20 21 21 22 22 23 24 24 25 25 26 26 27 27 28 28 29 30 31 31 32 33 33 32 33 33 33 34 35 34 35 36 36 37 37 37 38 39 38 39 40 41 41 42 42 43 43 44 44 45 46 46 47 48 48 49 49 50 50 49 50 51 51 ...
result:
wrong answer 11th lines differ - expected: '6', found: '5'