QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#803580#9868. GCDucup-team3584#WA 0ms3580kbC++232.2kb2024-12-07 17:40:032024-12-07 17:40:04

Judging History

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

  • [2024-12-07 17:40:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3580kb
  • [2024-12-07 17:40:03]
  • 提交

answer

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

ll slv(ll a, ll b) {
    ll res = 1e18;
    vector<ll> dp(a + 1, 1e18);
    {
        ll g = gcd(a, b);
        dp[a / g] = b / g;
    }
    for (int i = 0; i <= a + 2; ++i) {
        for (int j = 0; j < dp.size(); ++j) {
            cout << dp[j] << " ";
        }
        cout << endl;
        if (dp[0] == 0) {
            res = i;
            break;
        }
        vector<ll> ndp(a + 1, 1e18);
        for (int j = 0; j <= a; ++j) {
            if (dp[j] == 1e18) continue;
            if (j == 0) return i + 1;
            if (dp[j] == 0) return i + 1;
            ll g = gcd(j, dp[j]);
            if (0 <= j - g) {
                ll gg = gcd(j - g, dp[j]);
                ndp[(j - g) / gg] = min(ndp[(j - g) / gg], dp[j] / gg);
            }
            if (0 <= dp[j] - g) {
                ll gg = gcd(j, dp[j] - g);
                ndp[j / gg] = min(ndp[j / gg], (dp[j] - g) / gg);
            }
        }
        swap(dp, ndp);
    }
    return res;
}

ll slv_g(ll a, ll b) {
    auto dfs = [&](auto dfs, ll x, ll y) -> ll {
        if (x == 0 and y == 0) return 0;
        if (x == 0 or y == 0) return 1;
        ll g = gcd(x, y);
        ll res = min(dfs(dfs, x - g, y) + 1, dfs(dfs, x, y - g) + 1);
        return res;
    };
    return dfs(dfs, a, b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin >> q;
    while (q--) {
        //        int a = myRand(40) + 1, b = myRand(40) + 1;
        //        ll res1 = slv(a, b);
        //        ll res2 = slv_g(a, b);
        //        if (res1 != res2) {
        //            cout << "a = " << a << ", b = " << b << endl;
        //            cout << "res1 = " << res1 << ", res2 = " << res2 << endl;
        //            return 0;
        //        } else {
        //            cout << "OK" << endl;
        //        }
        ll a, b;
        cin >> a >> b;
        cout << slv(a, b) << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

input:

3
3 4
12 20
114 514

output:

1000000000000000000 1000000000000000000 1000000000000000000 4 
1000000000000000000 1 1000000000000000000 1000000000000000000 
1 0 1000000000000000000 1000000000000000000 
3
1000000000000000000 1000000000000000000 1000000000000000000 5 1000000000000000000 1000000000000000000 1000000000000000000 10000...

result:

wrong answer 1st lines differ - expected: '3', found: '1000000000000000000 1000000000000000000 1000000000000000000 4 '