QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716036 | #6440. Xingqiu's Joke | lamkappa | WA | 936ms | 7700kb | C++20 | 1.1kb | 2024-11-06 14:08:40 | 2024-11-06 14:08:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
int a, b; cin >> a >> b;
if(a > b) swap(a, b);
int c = b - a;
vector<int> fac;
for(int x=2; x*x <= c; x++){
if(c % x == 0){
fac.push_back(x);
while(c % x == 0) c /= x;
}
}
if(c > 1) fac.push_back(c);
unordered_set<int> vis;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
q.emplace(0, a);
while(!q.empty()){
auto[d, u] = q.top(); q.pop();
if(u == 1){
cout << d << '\n';
break;
}
if(vis.count(u)) continue;
vis.insert(u);
q.emplace(d + u - 1, 1);
for(auto p : fac){
if(u / p) q.emplace(d + u % p + 1, u / p);
q.emplace(d + p - u % p + 1, u / p + 1);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
5 4 7 9 8 32 84 11 35 2 1
output:
2 7 5 4 0
result:
ok 5 number(s): "2 7 5 4 0"
Test #2:
score: -100
Wrong Answer
time: 936ms
memory: 7700kb
input:
300 223528529 446621399 755625805 978718675 257717538 480810408 277875777 54782907 963091558 739998688 282469431 505562301 38752451 261845321 474429597 697522467 67026335 290119205 874629705 651536835 301964126 78871256 316864911 93772041 545942587 322849717 640801578 417708708 683070559 906163429 9...
output:
11 13 12 11 12 12 12 14 12 13 11 12 13 13 13 15 12 13 12 12 13 13 13 12 14 13 13 10 14 12 11 14 12 12 11 11 13 12 13 12 12 13 10 13 12 11 12 13 12 11 13 14 12 12 12 13 11 11 13 12 12 14 13 12 12 12 14 12 12 11 11 13 13 13 13 12 13 14 10 13 13 13 13 13 13 12 14 12 13 13 13 11 12 12 11 13 12 11 12 14 ...
result:
wrong answer 1st numbers differ - expected: '12', found: '11'