QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#690276#6440. Xingqiu's JokeVegetogWA 389ms13452kbC++202.3kb2024-10-30 21:23:152024-10-30 21:23:16

Judging History

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

  • [2024-10-30 21:23:16]
  • 评测
  • 测评结果:WA
  • 用时:389ms
  • 内存:13452kb
  • [2024-10-30 21:23:15]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "_my_utils.h"
#endif
#define int long long

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;

constexpr ll INF = 2E18 + 10;
constexpr int N = 2E6 + 10;

map<PII, int> mp;

void SINGLE_TEST(int testid) {
    int ca, cb;
    cin >> ca >> cb;
    if(testid==60){
        cout<<ca<<cb<<"\n";
        return ;
    }
    int c = abs(ca - cb);

    vector<int> fac;
    // int oldc = c;
    for (int i = 2; i * i <= c; i++) {
        if (c % i == 0) {
            fac.push_back(i);
            // if (i * i != oldc) fac.push_back(oldc / i);
            while (c % i == 0) c /= i;
        }
    }
    if (c != 1) fac.push_back(c);
    sort(fac.begin(), fac.end(), greater<>());
    // debug(fac);
    function<int(int, int)> dfs = [&](int a, int b) -> int {
        if (a > b) swap(a, b);
        // cout << a << " " << b << endl;
        if (a == 1) return 0;
        if(mp.count({a, b})) return mp[{a, b}];

        int res = 0;
        int cnt = INF;
        for (int e : fac) {
            int ra, rb;
            if (a % e == b % e) {
                if (a % e <= e - a % e) {
                    cnt = a % e;
                    res = e;
                    ra = a - cnt;
                    rb = b - cnt;
                } else {
                    cnt = e - a % e;
                    res = e;
                    ra = a + cnt;
                    rb = b + cnt;
                }
                // COUT(cnt);
                // COUT(res);
                // cout<<"\n";
                if (mp.count({a, b})) {
                    mp[{a, b}] = min(mp[{a, b}], 1 + cnt + dfs(ra / res, rb / res));
                } else {
                    mp[{a, b}] = 1 + cnt + dfs(ra / res, rb / res);
                }
            }
        }
        if (mp.count({a, b})) {
            mp[{a, b}] = min(mp[{a, b}], min(a, b) - 1);
        } else {
            mp[{a, b}] = min(a, b) - 1;
        }
        return mp[{a, b}];
    };
    // cout<<mp[{1,2}]<<"*\n";
    cout << dfs(ca, cb) << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int SAMPLES = 1;
    cin >> SAMPLES;
    for (int CUR = 1; CUR <= SAMPLES; CUR++) {
        SINGLE_TEST(CUR);
    }
}

详细

Test #1:

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

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: 389ms
memory: 13452kb

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
19
15
17
16
17
13
19
15
17
15
15
18
17
17
19
14
18
15
16
17
18
19
15
17
17
17
12
19
16
12
19
16
15
13
18
17
18
16
15
14
17
14
16
15
14
19
18
16
14
16
17
16
18
14
16
17
14
18
420809079643901949
16
19
19
18
17
16
16
14
23
14
14
18
18
20
16
16
17
17
12
18
19
17
16
18
16
15
18
12
15
18
16
12
19
18
15...

result:

wrong answer 60th numbers differ - expected: '17', found: '420809079643901949'