QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572632#6440. Xingqiu's Jokeji_114514WA 461ms3760kbC++201.7kb2024-09-18 15:43:302024-09-18 15:43:30

Judging History

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

  • [2024-09-18 15:43:30]
  • 评测
  • 测评结果:WA
  • 用时:461ms
  • 内存:3760kb
  • [2024-09-18 15:43:30]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 1e6 + 10;


void solve()
{
    int a, b; cin >> a >> b;
    if (a > b)swap(a, b);
    int d = b - a, s = d;
    vector<int>p;
    for (int i = 2; i <= d / i; i++) {
        if (d % i == 0) {
            p.push_back(i);
            while (d % i == 0)d /= i;
        }
    }
    if (d > 1)p.push_back(d);
    sort(p.begin(), p.end());
    priority_queue < pair<int, pair<int, int>>>heap;
    map<pair<int, int>, int>cnt;
    heap.push({ 0, {a, 1} });
    int res = a - 1;
    while (!heap.empty()) {
        auto q = heap.top(); heap.pop();
        int dist = -q.first, u = q.second.first, k = q.second.second;
        if (cnt.count(q.second) && cnt[q.second] <= dist || dist >= res)continue;
        if (u == 1) {
            res = min(res, dist);

            continue;
        }
        else cnt[q.second] = dist;
        for (auto d : p) {
            if (s / k % d == 0) {
                if (u % d == 0) {
                    heap.push({ -dist - 1, {u / d, k * d} });
                }
                else if (u < d) {
                    res = min(res, u - 1 + dist);
                    heap.push({ -(dist + d - u % d + 1), {u / d + 1, k * d} });
                }
                else {
                    heap.push({ -(dist + d - u % d + 1), {u / d + 1, k * d} });
                    heap.push({ -(dist + u % d + 1), {u / d, k * d} });
                }
            }
        }
    }
    cout << res << '\n';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while (t--)solve();
    return 0;
}

详细

Test #1:

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

input:

5
4 7
9 8
32 84
11 35
2 1

output:

2
7
5
4
0

result:

ok 5 number(s): "2 7 5 4 0"

Test #2:

score: -100
Wrong Answer
time: 461ms
memory: 3760kb

input:

300
223528529 446621399
755625805 978718675
257717538 480810408
277875777 54782907
963091558 739998688
282469431 505562301
38752451 261845321
474429597 697522467
67026335 290119205
874629705 651536835
301964126 78871256
316864911 93772041
545942587 322849717
640801578 417708708
683070559 906163429
9...

output:

12
755625804
15
17
739998687
17
13
474429596
15
651536834
15
15
18
20
683070558
692597097
14
18
15
717331879
720314105
759215467
19
17
17
684317381
17
12
595298358
16
12
644264512
21
676147383
13
629131212
507320902
18
16
15
14
619341996
14
24
15
14
765154269
516093796
497660494
14
16
26
16
18
14
19...

result:

wrong answer 2nd numbers differ - expected: '19', found: '755625804'