QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275243 | #6519. X Equals Y | ucup-team1321# | WA | 5ms | 3636kb | C++23 | 3.2kb | 2023-12-04 15:32:46 | 2023-12-04 15:32:46 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
vector<int> convert(int x,int b)
{
if(x==0) return {0};
vector<int>res;
while(x)
res.emplace_back(x%b),x/=b;
reverse(res.begin(),res.end());
return res;
}
vector<int>get_factor(int n)
{
vector<int>res;
for(int i=1;i*i<=n;i++)
if(n%i==0) res.emplace_back(i);
res.emplace_back(n);
return res;
}
void solve()
{
int x,y,A,B;
cin>>x>>y>>A>>B;
int sx=sqrt(x),sy=sqrt(y);
for(int a=2;a<=min(sx,A);a++)
{
vector<int>s=convert(x,a);
int l=2,r=B,b=0;
auto check=[=](int x)
{
long long sum=0;
for(int v:s)
{
sum=sum*x+v;
if(sum>y) return false;
}
return true;
};
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid)) b=mid,l=mid+1;
else r=mid-1;
}
long long sum=0;
bool flag=true;
for(int v:s)
{
sum=sum*b+v;
if(v>=b||sum>y)
{
flag=false;
break;
}
}
if(sum==y&&flag)
{
cout<<"YES\n";
cout<<a<<" "<<b<<"\n";
return;
}
}
for(int b=2;b<=min(sy,B);b++)
{
vector<int>s=convert(y,b);
int l=2,r=A,a=0;
auto check=[=](int x)
{
long long sum=0;
for(int v:s)
{
sum=sum*x+v;
if(sum>x) return false;
}
return true;
};
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid)) a=mid,l=mid+1;
else r=mid-1;
}
long long sum=0;
bool flag=true;
for(int v:s)
{
sum=sum*a+v;
if(v>=a||sum>x)
{
flag=false;
break;
}
}
if(sum==x&&flag)
{
cout<<"YES\n";
cout<<a<<" "<<b<<"\n";
return;
}
}
if(x>y)
{
vector<int>p=get_factor(x-y);
for(int m:p)
{
int d=(x-y)/m;
int b=max(m+1,sy+1),a=b+d;
if(a<sx+1)
{
int t=sx+1-a;
b+=t,a+=t;
}
if(a<=x/(m+1))
{
int t=x/(m+1)+1-a;
a+=t,b+=t;
}
if(b<=y/(m+1))
{
int t=y/(m+1)+1-b;
a+=t,b+=t;
}
int n=x-m*a;
if(n<0) continue;
if(a<=A&&b<=B)
{
cout<<"YES\n";
cout<<a<<" "<<b<<"\n";
return;
}
}
cout<<"NO\n";
return;
}
else if(x<y)
{
vector<int>p=get_factor(y-x);
for(int m:p)
{
int d=(y-x)/m;
int a=max(m+1,sx+1),b=a+d;
if(b<sy+1)
{
int t=sy+1-b;
a+=t,b+=t;
}
if(a<=x/(m+1))
{
int t=x/(m+1)+1-a;
a+=t,b+=t;
}
if(b<=y/(m+1))
{
int t=y/(m+1)+1-b;
a+=t,b+=t;
}
int n=x-m*a;
if(n<0) continue;
if(a<=A&&b<=B)
{
cout<<"YES\n";
cout<<a<<" "<<b<<"\n";
return;
}
}
cout<<"NO\n";
return;
}
else
{
cout<<"YES\n";
cout<<2<<" "<<2<<"\n";
return;
}
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
6 1 1 1000 1000 1 2 1000 1000 3 11 1000 1000 157 291 5 6 157 291 3 6 10126 114514 789 12345
output:
YES 2 2 NO YES 2 10 YES 4 5 NO YES 6 10
result:
ok correct (6 test cases)
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3636kb
input:
1000 920 661 756 534 52 454 31 218 980 77 812 6 729 733 289 660 161 643 21 475 602 525 329 274 782 167 279 113 875 100 388 16 426 498 341 417 433 751 312 39 91 50 47 39 941 388 247 46 725 808 148 486 945 405 700 145 647 509 152 445 45 564 16 468 843 40 530 3 722 36 323 22 568 472 443 41 38 749 25 42...
output:
YES 590 331 YES 14 148 NO YES 244 246 NO YES 77 66 YES 25 10 NO YES 214 286 NO NO NO NO YES 406 136 YES 96 73 YES 12 185 NO NO NO YES 10 247 NO NO YES 16 5 YES 132 101 NO YES 701 297 NO YES 45 174 NO YES 65 28 NO NO YES 89 49 YES 6 5 NO NO NO NO NO YES 282 87 NO YES 170 157 YES 17 25 YES 278 35 NO N...
result:
wrong answer you didn't find a solution but jury did (test case 19)