QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#803492 | #9868. GCD | ucup-team3584# | WA | 0ms | 3648kb | C++23 | 1.7kb | 2024-12-07 17:20:22 | 2024-12-07 17:20:22 |
Judging History
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);
dp[a] = b;
for (int i = 0; i <= a + 2; ++i) {
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;
ll g = gcd(j, dp[j]);
if (0 <= j - g) ndp[j - g] = min(ndp[j - g], dp[j]);
if (0 <= dp[j] - g) ndp[j] = min(ndp[j], dp[j] - g);
}
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(30) + 1, b = myRand(30) + 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;
// }
ll a, b;
cin >> a >> b;
cout << slv(a, b) << "\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
3 3 4 12 20 114 514
output:
3 4 6
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3648kb
input:
990 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 2 3 2 4 2...
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 4 2 3 3 2 3 4 2 3 3 2 3 4 2 3 3 2 3 4 2 3 3 2 3 4 2 3 3 2 3 4 2 ...
result:
wrong answer 675th lines differ - expected: '5', found: '6'