QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209932 | #4206. Event Hopping | HossamHero7# | 10 | 734ms | 101248kb | C++14 | 1.2kb | 2023-10-10 19:52:45 | 2024-07-04 02:18:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int n;
vector<vector<int>> adj;
vector<int> bfs(int src){
queue<int> q;
q.push(src);
vector<int> dep(n,1e9);
dep[src] = 0;
while(q.size()){
int node = q.front(); q.pop();
for(auto ch : adj[node]){
if(dep[ch] != 1e9) continue;
q.push(ch);
dep[ch] = dep[node] + 1;
}
}
return dep;
}
void solve(){
int q;
cin>>n>>q;
adj.resize(n);
pair<int,int> v[n];
for(auto &[s,e] : v) cin>>s>>e;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i == j) continue;
if(v[j].first<=v[i].second&&v[i].second<=v[j].second) adj[i].push_back(j);
}
}
vector<vector<int>> dis(n);
for(int src=0;src<n;src++) dis[src] = bfs(src);
while(q--){
int s,e;
cin>>s>>e;
int ans = dis[s-1][e-1];
if(ans == 1e9) cout<<"impossible"<<endl;
else cout<<ans<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
100000 100000 825913690 825916363 333322014 333324481 302015784 302018251 841002775 841005448 810249910 810252583 803554045 803556718 379590599 379593066 413477311 413479778 304105333 304107800 856802878 856805551 355907399 355909866 365590374 365592841 813775597 813778270 816058339 816061012 383873...
output:
result:
Subtask #2:
score: 10
Accepted
Test #13:
score: 10
Accepted
time: 105ms
memory: 8568kb
input:
1000 100 67878298 387720407 270457472 922959000 286470357 618323410 260791474 282940414 301337446 553875076 478221503 724555102 380447228 437131400 191801427 465825895 366088873 431222136 49483883 103442781 699926238 720636919 253150351 291688158 411085513 727726933 444078045 496386017 420626857 822...
output:
1 2 2 impossible 1 2 1 2 impossible 2 2 impossible impossible impossible 1 impossible impossible impossible impossible impossible 2 impossible 2 impossible 1 1 impossible 1 1 1 1 impossible 2 impossible 2 impossible 1 1 impossible impossible impossible 1 2 impossible impossible 1 2 impossible imposs...
result:
ok 100 lines
Test #14:
score: 0
Accepted
time: 734ms
memory: 11000kb
input:
1000 100 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 100...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 100 lines
Test #15:
score: 0
Accepted
time: 9ms
memory: 7060kb
input:
1000 100 219652137 219887840 411750082 411985785 295784206 296019909 323361457 323597160 263257192 263492895 228373148 228608851 311812010 312047713 189246450 189482153 197024649 197260352 214230968 214466671 209045502 209281205 282113432 282349135 277870778 278106481 394308060 394543763 318175991 3...
output:
999 998 998 997 997 997 996 996 996 996 995 995 995 995 995 994 994 994 994 994 994 993 993 993 993 993 993 993 992 992 992 992 992 992 992 992 991 991 991 991 991 991 991 991 991 990 990 990 990 990 990 990 990 990 990 989 989 989 989 989 989 989 989 989 989 989 988 988 988 988 988 988 988 988 988 ...
result:
ok 100 lines
Test #16:
score: 0
Accepted
time: 137ms
memory: 9620kb
input:
1000 100 146460236 650840147 213248988 712234443 271625877 765585418 268035474 762542588 155957999 659365570 108300122 614352264 161735587 665204546 244432982 734605513 84404294 596250403 472975048 964576612 128756912 628710941 130473656 631636782 324178293 813816145 197620586 692901130 353485130 84...
output:
impossible 1 impossible impossible 1 impossible impossible impossible 1 1 impossible 1 impossible 1 impossible impossible 1 1 impossible impossible 1 impossible 1 1 1 impossible impossible impossible impossible 1 1 1 impossible impossible impossible impossible 1 1 impossible impossible 1 1 1 1 impos...
result:
ok 100 lines
Test #17:
score: 0
Accepted
time: 7ms
memory: 7060kb
input:
1000 100 734527256 734722851 176171640 176781511 73713312 74323183 347545391 348155262 741959866 742155461 727094646 727290241 304244550 304854421 256064741 256674612 692278736 692474331 678391491 678587086 757020681 757216276 324370293 324980164 327419648 328029519 720248821 720444416 253015386 253...
output:
1 impossible 1 impossible 246 334 impossible impossible impossible 477 impossible 379 impossible impossible 393 196 impossible 271 122 impossible impossible impossible impossible impossible 207 impossible impossible 190 impossible impossible impossible impossible impossible impossible impossible imp...
result:
ok 100 lines
Test #18:
score: 0
Accepted
time: 9ms
memory: 7064kb
input:
1000 100 549 550 689 690 273 274 760 761 414 415 639 640 420 421 592 593 308 309 55 56 952 953 181 182 2 3 476 477 262 263 329 330 261 262 875 876 78 79 711 712 771 772 871 872 328 329 585 586 185 186 471 472 191 192 611 612 758 759 538 539 24 25 518 519 903 904 748 749 547 548 435 436 81 82 459 460...
output:
impossible impossible impossible 554 impossible impossible impossible 661 712 333 impossible impossible impossible impossible impossible impossible 329 impossible 101 416 impossible 268 impossible 676 impossible 131 impossible impossible impossible 337 impossible 417 impossible 231 impossible 146 im...
result:
ok 100 lines
Test #19:
score: 0
Accepted
time: 38ms
memory: 7796kb
input:
1000 100 41916637 42739142 57513660 58326077 21867551 172652993 148410501 243619298 80759769 81439087 1165860 77201426 122988614 155997027 100181236 100563028 185001902 185375949 176810589 177691863 141890410 142849915 92309958 240703409 40538462 236387490 22164234 22167602 144201862 144991292 19678...
output:
2 1 2 impossible impossible impossible impossible 1 1 3 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 1 2 impossible impossible impossible impossible 1 impossible impossible 2 impossible 2 impossible 1 impossible impossible impossible i...
result:
ok 100 lines
Test #20:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
5 2 1 3 2 4 4 7 7 9 3 7 1 4 3 2
output:
2 impossible
result:
ok 2 lines
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #21:
score: 15
Accepted
time: 252ms
memory: 101248kb
input:
5000 100000 444771902 444813193 517939554 517980845 420657958 420699249 565300331 565341622 489902965 489944256 550146534 550187825 621579964 621621255 541970916 542012207 504932889 504974180 509970391 510011682 548990386 549031677 531606875 531648166 611628833 611670124 424167693 424208984 43593562...
output:
4999 4998 4998 4997 4997 4997 4996 4996 4996 4996 4995 4995 4995 4995 4995 4994 4994 4994 4994 4994 4994 4993 4993 4993 4993 4993 4993 4993 4992 4992 4992 4992 4992 4992 4992 4992 4991 4991 4991 4991 4991 4991 4991 4991 4991 4990 4990 4990 4990 4990 4990 4990 4990 4990 4990 4989 4989 4989 4989 4989 ...
result:
ok 100000 lines
Test #22:
score: -15
Time Limit Exceeded
input:
5000 100000 688560220 703238347 121237680 134739514 589367489 602957567 728869127 745336729 9219545 23878334 488274497 501448797 849072503 861443731 23334524 37448893 956275044 970586285 583628356 597394100 810104747 824856103 110253553 124899493 522891845 536665379 912913517 928831291 329446513 344...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #28:
score: 0
Time Limit Exceeded
input:
100000 100 339859414 339860443 735166371 735174392 348212836 348213865 888215072 888223093 792396206 792404227 329405875 329405966 323863609 323864638 349411621 349412650 805520775 805526215 780236547 780238983 878461536 878469557 329490782 329490797 689599070 689607091 333606181 333607210 778431645...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #35:
score: 0
Time Limit Exceeded
input:
100000 100000 903318459 905410836 903528407 905653109 925180437 927048927 473524826 475597377 362562616 364539688 644980844 646918450 242583398 244653279 506338025 508361063 481496693 483530832 970053326 972147109 794840350 796900045 130664210 132709680 634100524 636336820 844429264 846504591 652483...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
0%