QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275224#6519. X Equals Yucup-team1321#WA 0ms3632kbC++232.5kb2023-12-04 15:18:402023-12-04 15:18:41

Judging History

你现在查看的是最新测评结果

  • [2023-12-04 15:18:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2023-12-04 15:18:40]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
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;
    }
  }
  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;
      }
      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;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr),cout.tie(nullptr);
  int T;
  cin>>T;
  while(T--)
    solve();
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

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: 0ms
memory: 3632kb

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
YES
106 8
NO
YES
10 247
NO
NO
YES
16 5
YES
132 101
NO
YES
701 297
NO
YES
45 174
YES
59 18
YES
65 28
YES
58 12
NO
YES
89 49
YES
6 5
YES
60 13
NO
NO
YES
88 87
NO
YES
282 87
NO
YE...

result:

wrong answer wrong solution, (722 in base 106) != (36 in base 8) (test case 18)