QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89269#5259. Skills in PillsdalfasewfWA 17ms3304kbC++141.5kb2023-03-19 14:43:182023-03-19 14:43:20

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:43:20]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3304kb
  • [2023-03-19 14:43:18]
  • 提交

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){
            if(!R[x-1]){
                ans+=(n-sx)/x+(n-sy)/y;
                break;
            }
            e=R[x-1]*y+sy;
        }
        else {
            if(!L[y-1]){
                ans+=(n-sx)/x+(n-sy)/y;
                break;
            }
            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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 3304kb

input:

3 9 20

output:

9

result:

wrong answer 1st lines differ - expected: '8', found: '9'