QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#393945#1881. Roads of the EmpiredeepthoughtWA 3ms3880kbC++14780b2024-04-19 17:18:012024-04-19 17:18:02

Judging History

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

  • [2024-04-19 17:18:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3880kb
  • [2024-04-19 17:18:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll n, u, v;

ll find_prev(int y){
	int res = n / y;
	int x = ((res + 1) * y) - n;
	if(x < y && x >= 1) return x;
	else return -1;
};


int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--) {
		cin >> n >> u >> v;
		map <long long, int> m;
		if(u == v) cout << 0 << "\n";
		else {
			if(u > v) swap(u, v);
			assert(u < v);
			int ans = -1;
			int cnt = 0;
			int x = v;
			while(x != -1) {
				m[x] = cnt;
				x = find_prev(x);
				cnt++;
			}
			x = u;
			cnt = 0;
			while(x != -1) {
				if(m.count(x) == 1) {
					ans = cnt + m[x];
					break;
				}
				x = find_prev(x);
				cnt++;
			}
			cout << ans << endl;
		}
	}

}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

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: 3524kb

input:

1
88 14 2

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

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

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: 3ms
memory: 3616kb

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: 1ms
memory: 3880kb

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'