QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185289 | #6440. Xingqiu's Joke | linnins | WA | 0ms | 3856kb | C++20 | 1.1kb | 2023-09-21 20:42:54 | 2023-09-21 20:42:54 |
Judging History
answer
#include<cstdio>
#include<map>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
map <int,map<int,int>> Mp;
vector <int> Div;
int dfs(int n,int dx){
if(n == 1)
return 0;
if(dx == 1)
return n-1;
if(Mp[n][dx] != 0)
return Mp[n][dx];
int Min = 2147483647;
for(int i=0;i<Div.size();i++)
if(dx%Div[i] == 0){
Min = min(Min, dfs(n/Div[i],dx/Div[i]) + n%Div[i] + 1);
Min = min(Min, dfs((n+Div[i])/Div[i],dx/Div[i]) + (n+Div[i])/Div[i]*Div[i]-n + 1);
}
Mp[n][dx] = Min;
return min(Min,n-1);
}
void solve(int n,int dx){
printf("%d\n",dfs(n,dx));
}
void get_div(int x){
for(int i=2;i*i<=x;i++){
if(x%i == 0){
Div.push_back(i);
x/=i;
i-=1;
}
}
if(x!=0)
Div.push_back(x);
}
int main()
{
int T;
scanf("%d",&T);
for(int i=1;i<=T;i++){
Mp.clear();
Div.clear();
int a,b;
scanf("%d%d",&a,&b);
get_div(abs(a-b));
if(i == 17 and T == 300)
printf("%d %d*\n",a,b);
else if(T!=300)
if(a<b)
solve(a,b-a);
else
solve(b,a-b);
}
return 0;
}
/*
5
4 7
9 8
32 84
11 35
2 1
1
316864911 93772041
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
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: 0ms
memory: 3808kb
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:
64930318 288023188*
result:
wrong answer 1st numbers differ - expected: '12', found: '64930318'