QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#802814 | #9868. GCD | ucup-team5234# | WA | 2ms | 4504kb | C++23 | 2.0kb | 2024-12-07 14:49:19 | 2024-12-07 14:49:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using VVVV = VV<VV<T>>;
#define rep(i,n) for(ll i=0ll;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
const long long INF = (1LL << 60);
const long long mod99 = 998244353;
const long long mod107 = 1000000007;
const long long mod = mod99;
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
#define all(i,v) for(auto& i : v)
#define UQ(v) sort(be(v)), v.erase(unique(be(v)), v.end())
#define LB(x,v) (lower_bound(be(v),(x))-(v).begin())
#define UB(x,v) (upper_bound(be(v),(x))-(v).begin())
#define dout() cout << fixed << setprecision(20)
#define randinit() srand((unsigned)time(NULL))
template<class T, class U> bool chmin(T& t, const U& u) { if (t > u){ t = u; return 1;} return 0; }
template<class T, class U> bool chmax(T& t, const U& u) { if (t < u){ t = u; return 1;} return 0; }
void solve(){
VV<ll> v(5001);
REP(i,2,5001){
for(ll j=i;j<=5000;j+=i) v[j].eb(i);
}
V<unordered_map<ll, ll>> mp(5001);
auto dfs = [&](auto &&dfs, ll a, ll b) -> ll {
if(b == 0) return 1;
ll g = gcd(a, b);
a /= g;
b /= g;
if(a == 1) return 2;
if(mp[a].count(b)) return mp[a][b];
ll ret = INF;
chmin(ret, dfs(dfs, a-1, b)+1);
ll y = INF, z = INF;
for(auto x:v[a]){
ll c = b%x;
chmin(ret, dfs(dfs, a, b - c) + c);
}
return mp[a][b] = ret;
};
ll t;
cin >> t;
rep(i,t){
ll a,b;
cin >> a >> b;
ll g = gcd(a, b);
a /= g;
b /= g;
cout << dfs(dfs, a, b) << '\n';
}
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t=1;
// cin >> t;
rep(i,t) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4148kb
input:
3 3 4 12 20 114 514
output:
3 4 6
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 4504kb
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 629th lines differ - expected: '6', found: '5'