QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533055 | #8643. Board Game | kimmoqt# | 0 | 2286ms | 8140kb | C++20 | 2.8kb | 2024-08-25 16:31:26 | 2024-08-25 16:31:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=5e4+5;
int N,M,K;
ll X[MX], dist[MX][3], T[MX];
vector<int> adj[MX];
string s;
bool cond[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N>>M>>K;
for(int i=0;i<M;i++) {
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin>>s;
for(int i=0;i<N;i++) cond[i+1]=s[i]-'0';
for(int i=1;i<=N;i++) T[i]=1e18;
vector<ll> v;
ll sum=0;
for(int i=1;i<=K;i++) {
cin>>X[i];
for(int j=1;j<=N;j++) {
for(int s=0;s<3;s++) {
dist[j][s]=1e18;
}
}
priority_queue<array<ll,3>> pq; // (distance, node, # stops)
pq.push({0,X[i],0});
dist[X[i]][0]=0;
while(!pq.empty()) {
auto [d,v,s]=pq.top(); pq.pop();
d=-d;
if(d>dist[v][s]) continue;
for(auto u:adj[v]) {
if(s+cond[u]<2 && dist[u][s+cond[u]]>d+1) {
dist[u][s+cond[u]]=d+1;
pq.push({-(d+1),u,s+cond[u]});
}
if(s==0 && i==1) {
// directly go without stop node
T[u]=min(T[u],dist[v][s]+1);
}
}
}
if(i==1) continue;
for(int j=1;j<=N;j++) {
if(cond[j]) {
for(auto k:adj[j]) {
if(cond[k]) {
dist[k][2]=min(dist[k][2],dist[j][1]+1);
}
}
}
}
ll d1=1e18,d2=1e18;
for(int j=1;j<=N;j++) {
d1=min(d1,dist[j][1]);
d2=min(d2,dist[j][2]);
}
v.push_back(d2-d1);
sum+=d1;
}
sort(v.begin(),v.end());
cond[X[1]]=0;
for(int i=0;i<=K-1;i++) {
// calculate current with dijsktra
// i nodes with double, K-i-1 nodes with single stop
// cost of edge of stop node is : 2*(K-i-1) + i
// initial cost is : sum - 2*(K-i-1) - 2*i
for(int j=1;j<=N;j++) {
dist[j][0]=dist[j][1]=1e18;
}
priority_queue<array<ll,3>> pq; // (distance, node)
pq.push({0,X[1],0});
dist[X[1]][0]=0;
T[X[1]]=0;
ll w=2*(K-i-1)+i;
while(!pq.empty()) {
auto [d,v,t]=pq.top(); pq.pop();
d=-d;
if(d<dist[v][t]) continue;
if(cond[v] && !t) {
if(dist[v][1]>dist[v][0]) {
dist[v][1]=dist[v][0];
pq.push({-dist[v][1],v,1});
}
continue;
}
for(auto u:adj[v]) {
if(cond[u]) {
if(dist[u][t]>dist[v][t]+w+1) {
dist[u][t]=dist[v][t]+w+1;
if(t) {
T[u]=min(T[u],(dist[v][t]+1)+sum-2*(K-i-1)-2*i);
} else {
T[u]=min(T[u],(dist[v][t]+1));
}
pq.push({-dist[u][t],u,t});
}
} else {
if(dist[u][t]>dist[v][t]+1) {
dist[u][t]=dist[v][t]+1;
if(t) {
T[u]=min(T[u],(dist[v][t]+1)+sum-2*(K-i-1)-2*i);
} else {
T[u]=min(T[u],(dist[v][t]+1));
}
pq.push({-dist[u][t],u,t});
}
}
}
}
// add the new change
if(i<K-1) {
sum+=v[i];
}
}
for(int j=1;j<=N;j++) {
cout<<T[j]<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 3
Accepted
time: 1087ms
memory: 5932kb
input:
3000 3000 3000 2378 2385 1560 2450 189 2980 44 1140 425 1843 167 1563 439 2010 7 951 1311 1370 1305 2085 150 1600 16 2469 431 2674 317 2191 1845 2918 2195 2917 1210 1577 125 1049 911 1160 504 2060 376 2420 1676 2969 1343 1576 284 1869 835 1989 273 1330 234 1906 1482 1524 2415 2460 388 2897 2177 2600...
output:
76 52 40 54 67 54 62 36 44 32 60 61 58 29 34 22 64 25 31 33 14 79 80 58 68 29 67 69 47 60 48 55 45 11 24 51 17 24 47 29 50 57 89 54 62 63 55 61 7 41 61 27 64 60 63 55 44 43 39 48 57 47 65 65 55 43 51 48 22 57 47 28 52 51 50 61 41 61 69 50 41 53 42 58 45 26 60 52 30 56 47 56 32 55 44 58 56 71 69 41 6...
result:
ok 3000 lines
Test #2:
score: 0
Time Limit Exceeded
input:
30000 30000 30000 11640 15443 5731 12870 5066 28442 11803 29263 2399 20658 4911 11282 676 1962 10390 19686 6117 6722 22155 28614 2932 14721 11403 13488 6697 22434 19113 26975 20347 20663 15743 16072 19116 25652 10891 19389 1373 27384 14607 29107 6192 29223 7196 10267 15467 16280 21828 26032 365 982 ...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 2286ms
memory: 4248kb
input:
3000 3000 3000 1391 1542 299 1578 1346 1528 46 1259 1513 2261 201 1717 56 1635 199 2327 847 882 1977 2161 465 1954 1723 2580 482 2105 906 2207 747 2742 2026 2845 1565 1809 295 311 278 2408 1215 2583 520 832 464 638 1223 1346 1799 2703 1022 2717 887 2160 619 2109 165 2478 879 1343 319 2463 56 815 109...
output:
-9209995169510666087 -9209995169510666093 -9209995169510666093 -9209995169510666085 -9209995169510666089 -9209995169510666109 -9209995169510666101 -9209995169510666089 -9209995169510666091 -9209995169510666101 -9209995169510666087 -9209995169510666083 -9209995169510666085 -9209995169510666083 -92099...
result:
wrong answer 1st lines differ - expected: '25', found: '-9209995169510666087'
Subtask #3:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 1674ms
memory: 3996kb
input:
3000 3000 3000 997 1695 884 1068 654 1853 6 520 947 2382 787 2407 818 1795 2347 2718 46 1560 1180 2169 582 1881 1080 1766 770 2877 365 419 365 749 1315 2536 223 1867 216 545 1311 1952 1598 2796 141 620 1681 2938 301 2204 866 1710 872 961 369 466 2160 2936 2295 2359 1310 1744 1572 2088 1111 2618 1680...
output:
-9209995169510296885 -9209995169510296914 -9209995169510296878 -9209995169510296641 -9209995169510296376 -9209995169510296898 -9209995169510296714 -9209995169510296458 -9209995169510296043 -9209995169510296844 -9209995169510296110 -9209995169510296741 -9209995169510296762 -9209995169510296521 -92099...
result:
wrong answer 1st lines differ - expected: '357', found: '-9209995169510296885'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 19
Accepted
time: 2ms
memory: 4080kb
input:
1500 3000 2 432 1120 324 1221 37 294 50 931 588 1149 178 887 460 517 268 533 649 935 123 1291 642 1025 1145 1489 630 1375 163 1407 842 1004 155 1300 296 1049 380 840 215 1224 283 981 211 1056 75 725 325 1437 591 680 1179 1253 876 1425 382 1230 1065 1436 612 784 121 770 349 633 140 1168 443 1019 103 ...
output:
6 6 7 4 5 5 6 3 5 7 5 6 5 5 5 6 6 6 3 5 5 6 3 6 5 6 3 3 6 6 5 6 4 5 7 6 6 6 5 2 5 5 6 5 4 7 4 4 5 5 5 7 6 5 5 3 6 6 5 5 6 5 6 4 5 6 4 7 3 6 6 4 5 5 4 7 6 6 6 7 5 3 5 6 4 6 4 6 4 6 4 6 5 6 3 4 6 4 5 3 6 5 6 7 4 6 5 6 7 5 4 6 5 5 6 6 6 4 5 5 6 4 4 6 6 6 6 6 6 6 6 5 6 6 5 6 4 6 5 6 6 6 6 5 7 4 6 4 6 5 ...
result:
ok 1500 lines
Test #24:
score: 0
Wrong Answer
time: 3ms
memory: 5856kb
input:
3000 2999 5 1183 2619 603 1077 245 1639 988 1253 70 2760 2292 2975 2483 2998 851 1914 214 968 1902 2025 1636 2835 62 2320 2082 2708 267 1972 613 2739 1273 2062 2173 2928 1028 1532 417 2184 291 899 608 2280 922 1566 670 1218 1023 1213 1193 2777 1142 2410 532 1558 67 1473 1041 1652 146 1877 727 2468 5...
output:
79 79 73 72 58 44 91 58 84 78 57 26 82 33 20 109 42 73 114 63 87 59 75 42 87 117 71 56 97 17 29 87 105 40 107 144 44 41 83 101 22 13 88 97 19 40 71 70 15 113 89 97 64 90 66 112 28 88 127 56 50 17 115 17 69 83 92 23 48 137 50 53 77 71 88 87 93 54 25 15 112 69 73 30 72 66 10 66 88 67 67 90 74 78 75 28...
result:
wrong answer 36th lines differ - expected: '143', found: '144'
Subtask #5:
score: 0
Wrong Answer
Test #44:
score: 23
Accepted
time: 53ms
memory: 8140kb
input:
50000 49999 2 25634 31370 8027 24849 12312 23307 3731 32856 28725 29829 23424 44542 9950 43281 17138 22049 29393 31047 24061 46387 861 3924 12114 24868 29242 36744 5090 11267 3946 26100 7151 22151 27368 49971 43548 44917 25373 45846 4117 43120 24675 34139 9043 21081 29857 41278 37558 41510 11300 402...
output:
114 120 159 152 68 38 72 118 129 123 155 95 61 164 142 103 72 58 122 97 89 73 64 57 174 59 67 114 111 99 122 60 100 61 20 112 104 103 114 168 113 70 104 93 105 49 118 119 111 177 91 88 87 102 162 146 94 178 108 87 98 130 90 152 41 71 61 145 77 79 94 70 133 80 89 124 122 105 67 38 133 173 118 126 85 ...
result:
ok 50000 lines
Test #45:
score: 0
Wrong Answer
time: 22ms
memory: 8112kb
input:
50000 49999 2 43895 48944 8580 43793 5509 33075 15981 49586 724 31051 32635 49692 4755 18049 14056 49273 29520 41218 6544 23864 43813 44446 9124 23567 7289 30800 4062 49229 35718 49417 2991 12579 4020 36609 33183 42312 2126 12426 1152 49261 33185 37634 42 3540 28164 28325 8375 41142 14587 25165 2779...
output:
24798 29882 416 7443 12670 5686 8669 28171 20672 31591 20660 22500 8308 1889 17095 14702 10490 29487 30974 18581 26460 3653 23778 3505 22605 31112 32425 13250 201 14390 29696 33551 30003 14838 8859 10816 26869 21931 5231 4625 14642 28208 24666 21836 31543 32282 21902 13506 22726 31819 10092 6395 326...
result:
wrong answer 1st lines differ - expected: '22033', found: '24798'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%