QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545526#4373. Swap SpacePhantomThreshold#RE 0ms0kbC++201.6kb2024-09-03 14:42:142024-09-03 14:42:15

Judging History

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

  • [2024-09-03 14:42:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-03 14:42:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
__int128 sq(__int128 x){
    __int128 sz=sqrtl(x);
    for (;(sz+1)*(sz+1)<=x;) sz++;
    for (;sz*sz>x;) sz--;
    return sz;
}
pair<ll,ll> solve(ll a,ll b,ll c){
    if (a==0){
        if (c%b!=0) return make_pair(-1LL,-1LL);
        return make_pair(-1LL,-c/b);
    }
    __int128 delta=(__int128)b*b-(__int128)4*a*c;
    if (delta<0) return make_pair(-1LL,-1LL);
    ll sqdt=sq(delta);
    if (sqdt*sqdt!=delta) return make_pair(-1LL,-1LL);
    ll x1=-b-sqdt;
    ll x2=-b+sqdt;
    if (x1%(2*a)!=0) x1=-1;
    else x1=x1/(2*a);
    if (x2%(2*a)!=0) x2=-1;
    else x2=x2/(2*a);
    return make_pair(x1,x2);
}

ll y,l;

int main(){
    cin >> y >> l;
    ll ans=10;
    for (ll b=11;b<=1000000;b++){
        vector<ll> digit;
        for (ll now=y;now;now/=b) digit.push_back(now%b);
        bool flag=1;
        ll res=0;
        reverse(digit.begin(),digit.end());
        for (auto x:digit){
            if (x>9){
                flag=0;
                break;
            }
            res=res*10+x;
        }
        if (!flag) continue;
       // cerr << b << " " << res << endl;
        if (res>=l) ans=max(ans,b);
    }
//    cerr << "ans : " << ans << endl;
    for (ll a=0;a<=9;a++){
        for (ll b=0;b<=9;b++){
            for (ll c=0;c<=9;c++){
                if (a*100+b*10+c<l) continue;
                auto [x1,x2]=solve(a,b,c-y);
                if (x1>0) ans=max(ans,x1);
                if (x2>0) ans=max(ans,x2); 
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
6 6
1 7
3 5
3 5

output:


result: