QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89470#5259. Skills in PillsyyyyxhTL 388ms38944kbC++141.0kb2023-03-20 09:45:192023-03-20 09:45: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-20 09:45:20]
  • 评测
  • 测评结果:TL
  • 用时:388ms
  • 内存:38944kb
  • [2023-03-20 09:45:19]
  • 提交

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;
}
map<pair<int,int>,int> mp;
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);
}
int dp(int u,int v){
	if(mp.find({u,v})!=mp.end()) return mp[{u,v}];
	int x=jump(u,v);
	if(x>n) return mp[{u,v}]=(n-u)/a+(n-v)/b+2;
	return mp[{u,v}]=min(dp(x-1,x)+(x-u-2)/a+(x-v-1)/b,dp(x,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;
	printf("%d\n",dp(0,0)-2);
	//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: 3540kb

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3432kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

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

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

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

input:

10 8 13

output:

2

result:

ok single line: '2'

Test #5:

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

input:

6 6 19

output:

6

result:

ok single line: '6'

Test #6:

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

input:

2 3 5

output:

3

result:

ok single line: '3'

Test #7:

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

input:

4 2 8

output:

6

result:

ok single line: '6'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

5 5 5

output:

2

result:

ok single line: '2'

Test #9:

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

input:

3 8 11

output:

4

result:

ok single line: '4'

Test #10:

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

input:

5 8 16

output:

5

result:

ok single line: '5'

Test #11:

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

input:

9 7 279

output:

70

result:

ok single line: '70'

Test #12:

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

input:

8 3 56

output:

25

result:

ok single line: '25'

Test #13:

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

input:

5 9 46

output:

14

result:

ok single line: '14'

Test #14:

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

input:

8 4 251

output:

93

result:

ok single line: '93'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

8 7 41

output:

10

result:

ok single line: '10'

Test #16:

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

input:

60 17 360

output:

27

result:

ok single line: '27'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

16 55 388

output:

31

result:

ok single line: '31'

Test #18:

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

input:

25 38 292

output:

18

result:

ok single line: '18'

Test #19:

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

input:

22 59 177

output:

11

result:

ok single line: '11'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

4 3 82

output:

50

result:

ok single line: '50'

Test #21:

score: 0
Accepted
time: 388ms
memory: 38944kb

input:

77 18 511543

output:

35070

result:

ok single line: '35070'

Test #22:

score: -100
Time Limit Exceeded

input:

37 32 987861

output:


result: