QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745783#9622. 有限小数DoubeecatWA 1ms3616kbC++172.1kb2024-11-14 11:36:272024-11-14 11:36:38

Judging History

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

  • [2024-11-14 11:36:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-11-14 11:36:27]
  • 提交

answer

/*
Undo the destiny.
*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
#define ll long long
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pii pair<int,int>
#define mp make_pair

char buf[1 << 20], *p1, *p2;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)?EOF: *p1++)
template <typename T> inline void read(T &t) {
    int v = getchar();T f = 1;t = 0;
    while (!isdigit(v)) {if (v == '-')f = -1;v = getchar();}
    while (isdigit(v)) {t = t * 10 + v - 48;v = getchar();}
    t *= f;
}
template <typename T,typename... Args> inline void read(T &t,Args&... args) {
    read(t);read(args...);
}

const ll mod = 998244353;
const double eps = 1e-10;
const ll inf = 1e9;

vector <ll> p;
const int qwq[3] = {1,2,5};
void dfs(int dep,ll val) {
    if (dep == 3) {
        p.push_back(val);
        return ;
    }
    for (ll v = val;v <= inf;v *= qwq[dep]) {
        dfs(dep + 1,v);
    }
}
ll a,b;
ll ans1,ans2;
void dfs1(int dep,ll val) {
    if (dep == 3) {
        ll kk = val / b;
        ll nowa = a * kk;
        int l = -1,r = p.size()-1;
        while (l + 1 < r) {
            int mid = (l + r) / 2;
            if (p[mid] * b - a * kk >= 0) r = mid;
            else l = mid; 
        }
        int pos = r;
        //cout << p[pos] * b << " " << a * kk << "\n";
        ll c = p[pos] * b - a * kk;
        //cout << c << " " << val << "\n";
        if (c < ans1) ans1 = c,ans2 = val;
        return ;
    }
    for (ll v = val;v <= inf;v *= qwq[dep]) {
        dfs1(dep + 1,v);
    }
}
ll work(ll x) {
    while (x % 2 == 0) x /= 2;
    while (x % 5 == 0) x /= 5;
    return x;
} 
void solve() {
    read(a,b);
    ll tmp = b / work(b);
    b = work(b);
    a *= tmp;
    ans1 = inf + 1;
    dfs1(1,b);
    cout << ans1 << " " << ans2 << "\n";
}

signed main() {
    dfs(1,1);
    sort(p.begin(),p.end());
    int T;read(T);
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3616kb

input:

4
1 2
2 3
3 7
19 79

output:

-1000000000 1000000000
1 3
1 14
3 316

result:

wrong answer Integer -1000000000 violates the range [0, 10^9]