QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610620 | #6440. Xingqiu's Joke | qinglu09 | WA | 671ms | 24572kb | C++14 | 1.2kb | 2024-10-04 16:39:41 | 2024-10-04 16:39:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
const int N=1e5+10;
#define lowbit(x) (x&-x)
map<PII,int>dp;
vector<int> get_prime_divisors(int x)
{
vector<int> res;
for(int i=2;i*i<=x;i++)
{
while(x%i==0)
{
res.push_back(i);
x/=i;
}
}
if(x!=1) res.push_back(x);
return res;
}
vector<int> get_divisors(int x)
{
vector<int> res;
for(int i=1;i*i<=x;i++)
{
if(x%i==0)
{
if(i!=1) res.push_back(i);
if(i!=x/i) res.push_back(x/i);
}
}
return res;
}
int dfs(int a,int c)
{
if(a==1) return 0;
if(c==1) return a-1;
if(dp.count({a,c})) return dp[{a,c}];
vector<int>path=get_prime_divisors(c);
int ans=1e9;
for(auto g:path)
{
int ans1=1e9;
if(a>=g) ans1=dfs((a-a%g)/g,c/g)+a%g+1;
int ans2=dfs((a+g-a%g)/g,c/g)+g-a%g+1;
ans=min({ans,ans1,ans2});
}
return dp[{a,c}]=ans;
}
void solve()
{
int a,b;
cin>>a>>b;
if(a>b) swap(a,b);
cout<<dfs(a,b-a)<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 671ms
memory: 24572kb
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:
12 19 15 17 16 17 13 19 15 17 15 16 18 17 17 19 16 18 15 16 17 18 19 15 17 17 17 13 19 16 13 19 16 15 13 18 17 18 16 15 14 17 14 16 15 14 19 18 16 14 16 17 16 18 14 16 17 14 18 17 16 19 19 18 17 16 16 14 23 14 14 18 18 20 16 16 17 17 12 18 19 17 16 18 16 17 18 12 15 18 16 13 19 18 16 18 17 15 13 16 ...
result:
wrong answer 12th numbers differ - expected: '15', found: '16'