QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#802919#9868. GCDucup-team055#WA 246ms3832kbC++203.8kb2024-12-07 15:11:512024-12-07 15:11:56

Judging History

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

  • [2024-12-07 15:11:56]
  • 评测
  • 测评结果:WA
  • 用时:246ms
  • 内存:3832kb
  • [2024-12-07 15:11:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}

namespace po167{
    struct UF
    {
        using _F = int;
        int _n;
        std::vector<_F> wei;
        std::vector<int> q;
        int component;
        UF(int n):_n(n), wei(n), component(n), par(n){
            for (int i = 0; i < n; i++){
                wei[i] =1, par[i] = i;
            }
        }
        void intialize(){
            for (auto x : q){
                wei[root(x)] = 1;
                par[x] = x;
            }
            component = (int)par.size();
            q = {};
        }
        //根っこを返す
        int root(int a){
            assert(0 <= a && a < _n);
            if (a == par[a]) return a;
            return par[a] = root(par[a]);
        }
        //trueなら1,falseなら0
        int same(int a, int b){
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            if(root(a) == root(b)) return 1;
            else return 0;
        }
        _F size(int a){
            return wei[root(a)];
        }
        //a,bが違う根っこの元なら結合する,結合したらtrueを返す
        bool unite(int a,int b){
            a = root(a), b = root(b);
            if (a == b) return false;
            if (a < b) std::swap(a, b);
            par[b] = a;
            q.push_back(b);
            wei[a] += wei[b];
            component--;
            return true;
        }
    private:
        std::vector<int> par;
    };
}
using po167::UF;

void solve();
// CITRUS CURIO CITY / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    ll A, B;
    cin >> A >> B;
    const int L = 5010;
    vector<ll> dp(L, ILL);
    auto f = [&](ll v, ll d) -> ll {
        return v - (v / d) * d;
    };
    ll ans = ILL;
    ll g = gcd(A, B);
    dp[g] = 0;
    rep(i, 1, L){
        // chmin(dp[i], f(A, i) + f(B, i));
        ll a = A / i, b = B / i;
        // if (i <= 20) cout << i << " : "  << dp[i] << " " << a << " " << b << endl;
        chmin(ans, dp[i] + min(a, b) + 1);
        for (int j = 2; j * i < L; j++){
            chmin(dp[j * i], dp[i] + f(a, j) + f(b, j));
        }
    }
    cout << ans << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

3
3 4
12 20
114 514

output:

3
4
6

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 246ms
memory: 3832kb

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 342nd lines differ - expected: '5', found: '4'