QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377030 | #1881. Roads of the Empire | Kevin5307 | WA | 53ms | 15376kb | C++20 | 1.4kb | 2024-04-04 20:54:56 | 2024-04-04 20:54:57 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int dist[144][144][144];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
memset(dist,0x3f,sizeof(dist));
for(int i=1;i<144;i++)
{
for(int j=1;j<=i;j++)
dist[i][j][j]=0;
for(int j=1;j<=i;j++)
for(int k=j+1;k<=i;k++)
if((j+i)%k==0)
dist[i][j][k]=dist[i][k][j]=1;
for(int a=1;a<=i;a++)
for(int b=1;b<=i;b++)
for(int c=1;c<=i;c++)
dist[i][b][c]=min(dist[i][b][c],dist[i][b][a]+dist[i][a][c]);
}
while(t--)
{
ll n,u,v;
cin>>n>>u>>v;
if(n<=140) cout<<(dist[n][u][v]==0x3f3f3f3f?-1:dist[n][u][v])<<'\n';
else if(u==v) cout<<"0\n";
else if(u==n||v==n) cout<<"-1\n";
else if((min(u,v)+n)%max(u,v)==0) cout<<"1\n";
else cout<<"-1\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 53ms
memory: 15216kb
input:
4 5 1 2 8 2 5 7 7 2 6 2 5
output:
1 1 -1 2
result:
ok 4 number(s): "1 1 -1 2"
Test #2:
score: 0
Accepted
time: 49ms
memory: 15364kb
input:
1 88 14 2
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 49ms
memory: 15220kb
input:
20 3 3 3 20 3 5 3 2 2 17 10 14 4 3 3 1 1 1 5 4 3 7 1 1 11 5 10 14 9 5 2 2 2 16 15 7 3 1 3 4 3 3 1 1 1 19 9 1 18 11 2 20 12 2 8 1 5 15 4 14
output:
0 -1 0 4 0 0 1 0 6 -1 0 -1 -1 0 0 3 2 -1 -1 -1
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 49ms
memory: 15284kb
input:
2000 8 2 7 2 2 1 64 37 21 77 30 25 84 39 62 3 3 1 34 15 32 62 41 60 99 8 96 22 9 17 89 1 19 26 6 15 26 14 25 22 15 17 99 99 30 89 41 29 52 16 38 95 58 69 31 23 10 65 24 21 67 25 7 79 3 65 62 30 20 90 75 62 62 14 56 55 38 50 4 1 3 76 18 59 58 34 5 61 21 13 98 34 89 38 33 16 83 29 46 46 6 5 28 25 8 46...
output:
-1 -1 -1 4 -1 -1 8 13 -1 5 2 2 7 4 -1 8 5 -1 9 -1 4 8 8 -1 3 -1 -1 4 3 4 6 3 5 3 4 -1 3 -1 -1 6 -1 -1 1 4 4 -1 -1 1 -1 0 4 7 -1 6 -1 3 -1 -1 -1 6 -1 -1 -1 -1 -1 4 2 5 -1 4 9 4 3 4 3 2 5 1 7 -1 10 -1 -1 -1 4 0 -1 -1 5 -1 -1 6 5 1 3 -1 0 8 11 2 -1 0 -1 12 -1 -1 5 6 0 -1 -1 1 8 0 -1 -1 2 6 0 5 -1 11 2 ...
result:
ok 2000 numbers
Test #5:
score: 0
Accepted
time: 53ms
memory: 15320kb
input:
2000 41 34 1 96 31 46 63 47 55 57 48 48 40 26 20 13 11 11 100 85 67 97 34 80 98 48 23 56 20 56 25 15 10 6 1 5 82 22 82 99 37 28 69 10 14 90 29 77 10 8 3 99 3 57 93 42 32 78 73 66 53 7 30 5 5 4 10 8 9 72 68 14 12 2 5 95 21 70 95 63 57 73 53 8 60 4 28 58 14 11 81 16 41 77 2 1 81 67 51 76 72 60 86 1 10...
output:
5 -1 1 0 -1 0 -1 6 9 -1 2 -1 -1 -1 2 8 3 3 4 7 1 -1 1 -1 -1 6 -1 8 -1 5 -1 1 7 2 -1 -1 6 2 4 2 -1 -1 -1 -1 0 5 2 -1 -1 6 3 6 7 3 -1 0 -1 -1 0 1 6 0 8 0 -1 -1 -1 6 -1 -1 5 6 6 -1 -1 -1 -1 -1 -1 -1 -1 3 2 -1 5 -1 0 5 -1 -1 4 7 0 5 4 6 -1 -1 7 4 2 -1 -1 -1 5 4 5 -1 -1 1 -1 6 6 3 -1 -1 7 -1 5 -1 -1 -1 4...
result:
ok 2000 numbers
Test #6:
score: -100
Wrong Answer
time: 49ms
memory: 15376kb
input:
100 1000000000000000000 598516350819009339 542438584254998413 1000000000000000000 109838532021251582 379790121599700364 1000000000000000000 368467904350174727 837836655562279882 1000000000000000000 384947108507418205 746463050934324258 1000000000000000000 915458376254369143 144866558378401506 100000...
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:
wrong answer 8th numbers differ - expected: '40', found: '-1'