QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89269 | #5259. Skills in Pills | dalfasewf | WA | 17ms | 3304kb | C++14 | 1.5kb | 2023-03-19 14:43:18 | 2023-03-19 14:43:20 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'