QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745794 | #9622. 有限小数 | Doubeecat | WA | 35ms | 3628kb | C++17 | 2.1kb | 2024-11-14 11:40:32 | 2024-11-14 11:40:40 |
Judging History
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 ((ll)p[mid] * b - a * kk < 0) l = mid;
else r = mid;
}
int pos = r;
//cout << p[pos] * b << " " << a * kk << "\n";
ll c = (ll)p[pos] * b - a * kk;
//cout << c << " " << val << "\n";
if (c < ans1 && c >= 0) 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 14 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 3628kb
input:
10000 11 12 28 53 17 60 2 35 17 181 80 123 68 141 79 163 71 99 13 64 33 61 15 32 16 61 11 86 33 74 128 143 40 53 7 23 30 31 5 6 86 181 73 91 13 23 71 81 1 2 7 38 117 160 33 83 129 151 88 153 25 58 16 19 19 141 95 124 43 96 71 139 11 59 106 109 93 152 34 43 17 99 1 57 20 159 16 25 5 73 159 170 172 17...
output:
4 3 25 53 35 3 4 7 11 1810 43 123 5 282 5 326 28 99 168 1 28 61 20 1 29 122 2 5375 8 37 15 143 12 265 3 368 1 31 2 3 9 362 18 91 10 23 10 81 0 1 5 19 1280 1 1 415 22 151 61 1224 8 29 3 19 46 705 15 62 124 3 21 17375 4 295 3 109 16 19 2 215 14 495 7 2850 44 19875 0 1 21 1825 110 17 7 179 15 13 5 68 7...
result:
wrong answer Jury found better answer than participant's 1 < 4 (Testcase 1)