QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#680449#7897. Largest DigitLemonWA 0ms3676kbC++141020b2024-10-26 21:05:292024-10-26 21:05:29

Judging History

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

  • [2024-10-26 21:05:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2024-10-26 21:05:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll la,ra,lb,rb;
ll num(ll x){
	ll res=0;
	while(x){
		x/=10;
		res++;
	}
	return res;
}
ll getans(ll x){
	ll ans=0;
	while(x){
		ans=max(ans,x%10);
		x/=10;
	}
	return ans;
}
ll ksm(int p){
	ll res=1,base=10;
	while(p){
		if(p%2) res*=base;
		base*=base;
		p/=2;
	}
	return res;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%lld%lld%lld%lld",&la,&ra,&lb,&rb);
		ll mn,mx;
		mn=la+lb;mx=ra+rb;
		//cin>>mn>>mx;
		ll a=mn,b=mx;
		if(b-a>=9){
			cout<<9<<endl;
			continue;
		}
		if(num(a)==num(b)){
			int f=1;
			while((a>10)&&(b>10)){
				ll ans1,ans2;
				ans1=a/(ksm(num(a)-1));
				ans2=b/(ksm(num(b)-1));
				if(ans1!=ans2){
					cout<<9<<endl;
					f=0;
					break;                                             
				}
				a%=(ksm(num(a)-1));
				b%=(ksm(num(b)-1));
			}
			if(f){
				cout<<max(getans(mn),getans(mx))<<endl;
			}
		}
		else cout<<9<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
178 182 83 85
2 5 3 6

output:

7
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3672kb

input:

1000
158260522 877914575 24979445 602436426
1 5 1101111 1101112
2 5 33333 33335
1 5 10111 10111
138996221 797829355 353195922 501899080
212 215 10302 10302
101100 101101 1 2
111 114 1101000 1101001
265804420 569328197 234828607 807497925
1110110 1110112 11100 11103
323 327 23 27
1 1 1 5
316412581 80...

output:

9
7
9
6
9
7
3
5
9
5
9
6
9
9
9
9
9
9
9
9
9
5
9
6
9
9
7
8
9
9
9
9
9
9
3
8
9
7
7
9
9
6
7
9
9
8
9
6
9
9
9
5
9
4
9
5
9
7
8
8
9
9
9
6
9
8
5
5
9
7
9
7
9
9
6
5
9
2
3
6
9
9
8
6
9
9
6
4
9
9
9
9
9
9
8
2
9
4
5
9
9
9
8
6
9
5
7
4
9
9
9
5
9
7
8
5
9
9
9
7
9
9
3
3
9
9
5
7
9
9
6
6
9
7
7
9
9
8
9
9
9
5
9
6
9
7
9
4
9
5
...

result:

wrong answer 67th lines differ - expected: '9', found: '5'