QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89474#5259. Skills in PillsyyyyxhWA 3ms3736kbC++141.1kb2023-03-20 09:50:282023-03-20 09:50:31

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-20 09:50:31]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3736kb
  • [2023-03-20 09:50:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=(x<<1)+(x<<3)+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
int n,a,b,tx,ty,ta,tb,g;
int exgcd(int a,int b,int &x,int &y){
	if(!b){x=1;y=0;return a;}
	int d=exgcd(b,a%b,y,x);
	y-=(a/b)*x;
	return d;
}
typedef long long ll;
int jump(int u,int v){
	if((v-u)%g) return 0x3f3f3f3f;
	ll x=(ll)tx*(v-u)/g;
	ll y=(ll)ty*(v-u)/g;
	int sx=x%tb;
	if(sx<=0) sx+=tb;
	int sy=y%ta;
	if(sy>=0) sy-=ta;
	return max(v+b*-sy,u+a*sx);
}
const int N=1000003;
int f[N][2];
bool vis[N][2];
int dp(int xs,bool t){
	if(vis[xs][t]) return f[xs][t];
	vis[xs][t]=1;
	int u=xs,v=xs;
	if(t) --u;else --v;
	int x=jump(u,v);
	if(x>n) return f[xs][t]=(n-u)/a+(n-v)/b+2;
	return f[xs][t]=min(dp(x,0)+(x-u-2)/a+(x-v-1)/b,dp(x,1)+(x-u-1)/a+(x-v-2)/b)+2;
}
int main(){
	a=read();b=read();n=read();
	g=exgcd(a,b,tx,ty);ta=a/g;tb=b/g;
	int x=jump(0,0);
	printf("%d\n",min(dp(x,0)+(x-2)/a+(x-1)/b,dp(x,1)+(x-1)/a+(x-2)/b));
	//for(auto cur:mp) printf("%d %d %d\n",cur.first.first,cur.first.second,cur.second);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3524kb

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3708kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 3ms
memory: 3544kb

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3736kb

input:

10 8 13

output:

4

result:

wrong answer 1st lines differ - expected: '2', found: '4'