QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189906#1187. Fast ForwardingKKT89AC ✓0ms3856kbC++171.1kb2023-09-28 01:26:542023-09-28 01:26:54

Judging History

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

  • [2023-09-28 01:26:54]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3856kb
  • [2023-09-28 01:26:54]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll t; cin >> t;
	vector<ll> v;
	vector<ll> vv;
	v.push_back(1);
	ll a=1;
	for(int i=0;;i++){
		vv.push_back(a);
		a*=3;
		ll k=0;
		for(ll p:vv){
			k+=p*2;
		}
		k+=a;
		if(k<=t){
			v.push_back(k);
		}
		else{
			break;
		}
	}
	ll ans=1e18;
    	for(int i=0;i<v.size();i++){
		ll cnt=2*(i+1)-1;
		ll cp=t;
		cp-=v[i];
		for(int j=i;j>=0;j--){
			cnt+=cp/vv[j];
			cp%=vv[j];
		}
		ans=min(ans,cnt);
	}
	vector<ll> f;
	vector<ll> ff;
	f.push_back(0);
	a=1;
	for(int i=0;;i++){
		ff.push_back(a);
		a*=3;
		ll k=0;
		for(ll p:ff){
			k+=p*2;
		}
		k+=a;
		k--;
		if(k<=t){
			f.push_back(k);
		}
		else{
			break;
		}
	}
	for(int i=0;i<f.size();i++){
		ll cnt=2*(i+1)-2;
		ll cp=t;
		cp-=f[i];
		for(int j=i;j>=0;j--){
			cnt+=cp/ff[j];
			cp%=ff[j];
		}
		ans=min(ans,cnt);
	}
	cout << ans << endl;
} 


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

19

output:

5

result:

ok answer is '5'

Test #2:

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

input:

13

output:

5

result:

ok answer is '5'

Test #3:

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

input:

123456789098765

output:

85

result:

ok answer is '85'

Test #4:

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

input:

51

output:

11

result:

ok answer is '11'

Test #5:

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

input:

0

output:

0

result:

ok answer is '0'

Test #6:

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

input:

3

output:

3

result:

ok answer is '3'

Test #7:

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

input:

4

output:

2

result:

ok answer is '2'

Test #8:

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

input:

1125899906842623

output:

99

result:

ok answer is '99'

Test #9:

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

input:

1125899906842523

output:

95

result:

ok answer is '95'

Test #10:

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

input:

16

output:

4

result:

ok answer is '4'

Test #11:

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

input:

17

output:

5

result:

ok answer is '5'

Test #12:

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

input:

18

output:

6

result:

ok answer is '6'

Test #13:

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

input:

137260754729764

output:

58

result:

ok answer is '58'

Test #14:

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

input:

137260754729765

output:

59

result:

ok answer is '59'

Test #15:

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

input:

137260754729766

output:

60

result:

ok answer is '60'

Test #16:

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

input:

16

output:

4

result:

ok answer is '4'

Test #17:

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

input:

118096

output:

20

result:

ok answer is '20'

Test #18:

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

input:

484

output:

10

result:

ok answer is '10'

Test #19:

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

input:

411782264189296

output:

60

result:

ok answer is '60'

Test #20:

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

input:

1085641823733384

output:

96

result:

ok answer is '96'

Test #21:

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

input:

167786964029788

output:

82

result:

ok answer is '82'

Test #22:

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

input:

334812692221484

output:

90

result:

ok answer is '90'

Test #23:

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

input:

595331521341901

output:

85

result:

ok answer is '85'

Test #24:

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

input:

9118177

output:

39

result:

ok answer is '39'

Test #25:

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

input:

23074720

output:

44

result:

ok answer is '44'

Test #26:

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

input:

33017934

output:

44

result:

ok answer is '44'

Test #27:

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

input:

1

output:

1

result:

ok answer is '1'

Test #28:

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

input:

2

output:

2

result:

ok answer is '2'