QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784542 | #1774. Customs Controls | xzf_200906 | WA | 108ms | 43688kb | C++14 | 2.0kb | 2024-11-26 15:18:28 | 2024-11-26 15:18:28 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
using namespace std;
set<pair<int,int> > ed;
vector<int> e[1000000];
int t[1000000],disS[1000000],disT[1000000],n,m,k;
void dij(int s,int dis[1000000]){
for(int i=1;i<=n;i++) dis[i]=-1;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
q.push({0,s});
while(!q.empty()){
pair<int,int> now=q.top();
q.pop();
int p=now.second;
if(dis[p]!=-1) continue;
dis[p]=now.first+t[p];
for(auto it:e[p]){
if(dis[it]==-1) q.push({dis[p],it});
}
}
}
bool fl1[1000000],fl2[1000000];
int col[1000000];
void fillOther(int lft1,int lft2){
for(int i=1;i<=n;i++){
if(col[i]==0){
if(lft1){
lft1--;
col[i]=1;
}
else{
lft2--;
col[i]=2;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++) cin>>t[i];
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
dij(1,disS);
dij(n,disT);
for(auto it:e[1]){
if(disT[it]+t[1]==disT[1]) fl1[it]=1;
}
for(int it:e[n]){
if(disS[it]+t[n]==disS[n]) fl2[it]=1;
}
int lft1=k,lft2=n-k;
fl1[1]=fl2[n]=1;
if(fl1[n]){
if(lft1<=1&&lft2<=1){
cout<<"impossible\n";
return 0;
}
if(lft1>1){
col[1]=col[n]=1;
lft1-=2;
}
else{
col[1]=col[n]=2;
lft2-=2;
}
fillOther(lft1,lft2);
for(int i=1;i<=n;i++) cout<<"XNS"[col[i]];
cout<<'\n';
return 0;
}
if(!lft1||!lft2){
fillOther(lft1,lft2);
for(int i=1;i<=n;i++) cout<<"XNS"[col[i]];
cout<<'\n';
return 0;
}
int cnt1=0,cnt2=0;
for(int i=1;i<=n;i++){
if(fl1[i]&&!fl2[i]) cnt1++;
if(!fl1[i]&&fl2[i]) cnt2++;
}
for(int i=1;i<=n;i++){
if(fl1[i]&&fl2[i]) continue;
if((fl1[i]&&cnt1<=cnt2)||(fl2[i]&&cnt1>cnt2)){
if(k>=(n>>1)){
col[i]=1;
lft1--;
}
else{
col[i]=2;
lft2--;
}
}
}
fillOther(lft1,lft2);
for(int i=1;i<=n;i++) cout<<"XNS"[col[i]];
cout<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 36008kb
input:
5 10 2 1 1 1 1 1 3 4 5 4 3 1 4 1 3 5 2 1 2 4 2 5 1 5 2 3
output:
NSSSN
result:
ok accepted
Test #2:
score: 0
Accepted
time: 0ms
memory: 35704kb
input:
10 9 5 1 1 1 1 1 1 1 1 1 1 9 5 7 1 8 1 10 1 5 3 6 1 2 1 3 2 4 1
output:
NNNNSSSSSN
result:
ok accepted
Test #3:
score: 0
Accepted
time: 0ms
memory: 37356kb
input:
2 1 2 6124 7094 2 1
output:
NN
result:
ok accepted
Test #4:
score: 0
Accepted
time: 0ms
memory: 37184kb
input:
2 1 1 6901 1417 2 1
output:
impossible
result:
ok accepted
Test #5:
score: 0
Accepted
time: 0ms
memory: 36452kb
input:
50 67 25 5 10 5 4 3 3 8 7 10 4 6 6 9 8 5 1 5 9 3 2 3 8 9 9 2 8 7 8 9 8 3 3 10 7 5 5 7 1 6 9 4 6 9 10 4 10 9 10 9 5 45 35 27 17 11 14 34 1 49 37 4 2 9 3 42 9 13 25 40 32 38 17 28 1 26 14 13 19 41 40 38 40 12 6 14 7 47 25 30 21 32 22 7 6 16 12 15 9 20 16 29 3 21 8 19 9 18 23 43 5 5 3 11 35 10 7 36 16 ...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSSSSSSS
result:
ok accepted
Test #6:
score: 0
Accepted
time: 7ms
memory: 36828kb
input:
100 99 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 34 11 79 3 36 30 59 24 83 14 88 23 19 9 44 19 91 11 40 14 58 37 99 30 45 12 81 66 38 35 73...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
result:
ok accepted
Test #7:
score: 0
Accepted
time: 0ms
memory: 37020kb
input:
200 400 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSN
result:
ok accepted
Test #8:
score: 0
Accepted
time: 3ms
memory: 35380kb
input:
400 2000 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
SNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS...
result:
ok accepted
Test #9:
score: 0
Accepted
time: 3ms
memory: 36036kb
input:
800 1600 400 6778 2494 1425 4552 1937 7148 830 9892 8936 4711 2727 7103 8171 3131 3086 8687 7433 3238 6572 1018 9461 9638 1484 666 3143 9266 5392 8490 5948 6927 9595 2267 7386 411 8292 5330 968 8697 1138 8303 5827 8830 8821 7204 2407 4636 985 7995 431 4492 6978 4675 2773 3208 6624 1770 6094 1576 590...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #10:
score: 0
Accepted
time: 0ms
memory: 36728kb
input:
1601 1637 800 11 20 4 18 4 15 7 15 4 4 3 8 16 18 9 7 9 16 9 4 16 3 11 14 19 2 19 20 15 5 2 8 6 10 8 14 20 8 10 6 9 13 16 5 14 19 18 13 7 17 19 18 9 15 3 2 12 2 2 12 3 3 16 5 4 16 8 17 10 3 14 18 15 13 3 10 14 5 4 18 18 10 9 14 14 7 5 4 12 13 7 13 4 8 13 20 14 6 3 6 18 1 5 20 7 11 1 1 11 5 16 2 11 7 ...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #11:
score: 0
Accepted
time: 7ms
memory: 35188kb
input:
10000 9999 500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
SSNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #12:
score: 0
Accepted
time: 10ms
memory: 37756kb
input:
10000 20000 5000 8295 3745 794 1318 1691 7504 9376 1326 507 2339 256 9868 9674 3268 6993 4296 3924 9424 3276 5493 3019 1786 832 6542 5285 2221 6770 1310 1695 3270 5800 1424 7943 8349 6731 1523 8935 4374 5 7139 808 5421 6233 7507 5372 4693 382 1098 1083 8487 1602 5114 9404 318 9440 4081 1355 38 6967 ...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #13:
score: 0
Accepted
time: 108ms
memory: 43688kb
input:
100000 200000 50000 6610 9169 2169 6552 433 1085 6451 9008 2102 5083 8156 6290 9891 531 7776 2219 6685 2750 6288 2201 2433 1734 4059 8849 7272 6446 279 6743 318 4626 1731 496 2821 7543 9915 143 8983 1939 4554 2999 8949 6805 7900 9442 4881 5738 3164 651 8646 7282 6329 2213 2211 6679 3677 2075 6931 79...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #14:
score: 0
Accepted
time: 49ms
memory: 39648kb
input:
100000 100010 50000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #15:
score: 0
Accepted
time: 50ms
memory: 42940kb
input:
100000 100048 50000 10 4 9 3 4 5 8 10 6 2 10 7 1 2 2 9 9 2 7 6 10 3 2 2 8 5 10 5 6 5 3 1 7 6 5 3 5 9 1 3 1 7 10 8 8 5 4 4 8 10 6 10 10 6 4 10 2 6 8 9 2 5 6 10 3 7 9 8 7 4 9 9 2 2 5 7 9 9 7 4 7 1 8 8 5 7 8 3 9 6 3 6 6 6 3 8 1 1 10 8 6 9 7 3 10 10 4 4 10 1 7 2 1 7 10 2 9 5 7 7 1 10 4 6 4 1 6 1 1 2 6 7...
output:
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok accepted
Test #16:
score: 0
Accepted
time: 98ms
memory: 43088kb
input:
100000 200000 1 3483 3913 2465 4127 2680 1151 6612 1498 6652 966 688 8449 312 9341 1289 2574 7250 2310 8421 5242 4799 7903 4517 8356 6465 5466 2562 2052 9897 8666 6149 9850 184 9535 9355 8845 7330 2183 1492 4985 2352 1362 1928 4940 5895 8893 2251 6792 4679 2146 2677 3667 4218 5797 8433 3462 8459 806...
output:
SNSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS...
result:
ok accepted
Test #17:
score: -100
Wrong Answer
time: 4ms
memory: 35368kb
input:
10 14 4 10000 10000 3921 6078 1 10000 10000 10000 10000 10000 10 6 1 2 1 8 10 8 3 5 1 3 5 4 1 6 10 2 10 4 10 7 10 9 1 7 1 9
output:
SNSNNNSSSS
result:
wrong answer an alternating shortest path existed