QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377021#1881. Roads of the EmpireKevin5307WA 1ms4008kbC++201.4kb2024-04-04 20:48:502024-04-04 20:48:51

Judging History

你现在查看的是最新测评结果

  • [2024-04-04 20:48:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4008kb
  • [2024-04-04 20:48:50]
  • 提交

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[44][44][44];
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<44;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<=40) 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<<"2\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4008kb

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: 0ms
memory: 3892kb

input:

1
88 14 2

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3976kb

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: -100
Wrong Answer
time: 1ms
memory: 3980kb

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
2
2
2
-1
8
2
2
5
2
2
7
4
-1
2
2
2
9
2
2
2
2
2
2
2
-1
2
2
2
2
3
2
2
4
-1
3
2
-1
2
2
2
1
2
4
2
2
1
-1
0
4
7
2
2
-1
2
-1
2
-1
2
-1
-1
-1
2
2
2
2
2
2
4
2
2
3
4
2
2
2
1
7
2
2
2
2
2
4
0
2
2
5
2
-1
2
2
1
2
2
0
2
2
2
-1
0
-1
2
2
-1
2
2
0
-1
-1
1
2
0
2
2
2
6
0
5
-1
2
2
2
-1
2
2
4
-1
1
-1
2
-1
-1
2
2
0
...

result:

wrong answer 3rd numbers differ - expected: '-1', found: '2'