QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89265#5259. Skills in PillsdalfasewfTL 0ms0kbC++141.2kb2023-03-19 14:38:212023-03-19 14:38:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-19 14:38:23]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-03-19 14:38:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[2000009];
ll n,m,k,x,y;
ll cnt,ans;
map<ll,ll>L,R;
ll f(ll e,ll cx,ll cy){
    return (n-e+cy)/x+(n-e+cy)/y;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    ll i,j,t;
    cin>>x>>y>>n;
    if(x==y){
        cout<<n/x+(n+1)/x;
        return 0;
    }
    for(i=1;i<=1000000;i++){
        if(!L[x*i%y])L[x*i%y]=i;
        if(!R[y*i%x])R[y*i%x]=i;
    }
    ll l=0,r=0;
    i=x,j=y;
    ll sx=0,sy=0;
    while(1){
        ll e;
        if(sx==sy)e=L[0]*x+sx;
        else if(sx<sy)e=R[x-1]*y+sy;
        else e=L[y-1]*x+sx;

//        cout<<e<<"\n";
        if(e>=n){
            ans+=(n-sx)/x+(n-sy)/y;
            break;
        }

        if(sx==sy)ans+=L[0]+R[0];
        else if(sx<sy)ans+=R[x-1]+(e-sx)/x;
        else ans+=L[y-1]+(e-sy)/y;

//    cout<<"A: "<<ans<<"\n";
        if(f(e,1,0)<f(e,0,1)){//x左移
//            cout<<"X\n";
            sx=e-1;
            sy=e;
        }
        else {//y左移
//            cout<<"Y\n";
            sx=e;
            sy=e-1;
        }
//        cout<<sx<<" "<<sy<<"\n";
    }
    cout<<ans;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3 9 20

output:


result: