QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#231849 | #6440. Xingqiu's Joke | zGoofy# | WA | 0ms | 3512kb | C++14 | 977b | 2023-10-29 17:09:48 | 2023-10-29 17:09:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<pair<int, int>, int>mp;
vector<int>cnt;
int dfs(int a, int t) {
if(a == 1) return 0;
if(t == 1) return a - 1;
if(mp[{a, t}]) return mp[{a, t}];
int res = a - 1;
for(auto i : cnt) {
if(t % i == 0) {
int tmp = dfs(a / i, t / i) + a % i + 1;
int tmp2 = dfs(a / i + 1, t / i ) + i - (a % i) + 1;
res = min({tmp, tmp2, res});
}
}
mp[{a, t}] = res;
return res;
}
void solve() {
int a, b;
cin >> a >> b;
if (a > b) {
swap(a, b);
}
int t = b - a;
for (int i = 2; i <= t; i++) {
if (t % i == 0) {
cnt.push_back(i);
while (t % i == 0) {
t /= i;
}
}
}
if (t != 1) {
cnt.push_back(t);
}
cout << dfs(a, b - a) << endl;
return;
}
signed main() {
ios::sync_with_stdio(false);
int tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3512kb
input:
5 4 7 9 8 32 84 11 35 2 1
output:
3
result:
wrong answer 1st numbers differ - expected: '2', found: '3'