QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377516#5117. Find MaximumXUAN_WA 6ms3604kbC++141.3kb2024-04-05 14:42:462024-04-05 14:42:46

Judging History

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

  • [2024-04-05 14:42:46]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3604kb
  • [2024-04-05 14:42:46]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
const int N = 1e5+7;
template <typename T> inline void read(T &x){
	T ch=getchar(),xx=1;x=0;
	while(!isdigit(ch)) xx=ch=='-'?-1:xx,ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	x*=xx;
}
template <typename T> void print(T x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+'0');
}
LL qpow(LL a,LL b){
	LL res=1;
	for(;b;b>>=1){
		if(b&1) res*=a;
		a*=a;
	}
	return res;
}
int ans;
LL L,R;
int l[30],r[30];
int nl,nr;
void calc(int p,int res,bool flag){ //flag = 1无限制 
	
	if(flag){
		ans=max(ans,res+nr+p*2);
		return;
	}
	if(p==0){
		ans=max(ans,res+nr);
		return;
	}
	calc(p-1,res+r[p],0);
	if(r[p]-1>=l[p]) calc(p-1,res+r[p]-1,1); 
	
}

int main(){
	int T;
	read(T);
	while(T--){
		
		nl=nr=0;
		read(L),read(R);
	
		LL tmp=L;
		ans = 0;
		while(tmp){
			l[++nl]=tmp%3;
			tmp/=3;
		}
		
		tmp=R;
		while(tmp){
			r[++nr]=tmp%3;
			tmp/=3;
		}
		
		
		if(nl==nr) calc(nr,0,0);
		else{
			ans=3*(nr-1);
			L=qpow(3,nr-1);
			
			tmp=L;
			nl=0; 
			while(tmp){
				l[++nl]=tmp%3;
				tmp/=3;
			}
			
			calc(nr,0,0);
		}
		print(ans);
		putchar('\n');
	}
	return 0;
}
 


/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

3
3
4
5
3
4
5
4
5
5

result:

ok 10 numbers

Test #2:

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

input:

5050
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61...

output:

2
3
3
4
5
5
5
6
6
6
6
6
6
7
7
7
8
8
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
10
10
10
10
10
10
10
10
10
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
3
3
4
5
5
5
6
6
6
6
6
6
7
7
7
8
8
8
8
8
8
8...

result:

ok 5050 numbers

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 3476kb

input:

10000
2924776299390853 348932224550662831
638290869233943020 897334616745111026
210780034220004669 279345354637770906
20574264013277469 387573622060864735
39441497975868873 806211034038773415
19845198891021950 243636832211738144
298454268109304380 988142879006387197
613847475002049291 86666797163210...

output:

98
112
109
97
97
99
99
112
100
107
109
113
99
100
111
111
109
92
98
101
100
101
113
100
100
99
98
99
101
110
98
97
100
111
100
99
101
110
108
97
100
113
110
100
110
100
110
107
111
111
109
107
100
100
100
100
100
98
100
100
100
98
100
100
99
101
101
98
100
97
101
112
112
110
99
111
96
96
100
97
101
...

result:

wrong answer 1st numbers differ - expected: '110', found: '98'