QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#843133#9868. GCDMonikaRE 0ms0kbC++171.2kb2025-01-04 16:57:082025-01-04 16:57:11

Judging History

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

  • [2025-01-04 16:57:11]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2025-01-04 16:57:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(a,b,c) for (a = b; a <= c; a ++)
#define rrep(a,c,b) for (a = c; a >= b; a --)
#define endl '\n'

typedef pair<int,int> pii;

const int N = 5005;
const int inf = 1e9 + 10;

int g[N][N];
int a, b;

void solve(){
    cin >> a >> b;

    int i, j;
    rep(i,0,a) rep(j,0,a){
        g[i][j] = inf;
    }

    queue <pii> q;
    q.push({0, 0});
    g[0][0] = 0;

    while (1){
        auto [x, y] = q.front(); q.pop();

        if (x == a){
            cout << g[x][y] + 1 << endl;
            return;
        }

        // cout << x << " , " << y << endl;

        int gcd = __gcd(a - x, b - y);

        if (x + gcd > a || y + gcd > a) continue;

        if (g[x][y + gcd] > g[x][y] + 1){
            g[x][y + gcd] = g[x][y] + 1;
            q.push({x, y + gcd});
        }

        if (g[x + gcd][y] > g[x][y] + 1){
            g[x + gcd][y] = g[x][y] + 1;
            q.push({x + gcd, y});
        }
    }
}

signed main(){
    ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);

    int T = 1;
    cin >> T;

    while (T --){
        solve();
    }

    system("PAUSE");
}                   

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
3 4
12 20
114 514

output:


result: