QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65095 | #5117. Find Maximum | Tntac7 | WA | 4ms | 3568kb | C++ | 1.7kb | 2022-11-27 15:56:34 | 2022-11-27 15:56:36 |
Judging History
answer
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define fi first
#define se second
typedef long long ll;
inline void solve()
{
string a1,a2;
ll l,r;
scanf("%lld%lld",&l,&r);
//cout << l << ' ' << r << '\n';
while(l)
{
int t=l%3;
char ch='0'+t;
l/=3;
a1=ch+a1;
}
int sum=0;
while(r)
{
int t=r%3;
sum+=t;
char ch='0'+t;
r/=3;
a2=ch+a2;
}
//cout << a1 << ' ' << a2 << '\n';
int len=a2.size();
sum+=len;
string ck1,ck2,ck3;
for(int i=0;i<len;i++) ck1+='2',ck3+='1';
ck2+='1';
for(int i=0;i+1<len;i++) ck2+='2';
int ans=0;
if(a2.size()>=a1.size()+1)
{
//cout << ck1 << ' ' << ck3 << ' ' << ck2 << '\n';
//puts("1111");
if(a2==ck1)
{
ans=len*2+len;
}
else
{
if(a2[0]=='2'||a2==ck2)
{
ans=len*2-1+len;
}
else
{
ans=(len-1)*2+len-1;
}
bool flag=true;
for(int i=0;i<len;i++)
{
if(a2[i]<'1')
{
flag=false;
break;
}
}
if(a2[0]=='2'||flag)
{
ans=max(ans,len*2);
}
}
if(len>=2&&a2[0]=='1'&&a2[1]=='2')
{
ans=max(ans,len+(len-1)*2);
}
ans=max(ans,sum);
printf("%d\n",ans);
}
else
{
int ans1=0;
for(int i=0;i<len;i++) ans1+=a2[i]-'0';
ans1+=len;
int wi=0;
for(int i=0;i<len;i++)
{
if(a2[i]>a1[i])
{
wi=i;
break;
}
}
a2[wi]-=1;
for(int i=wi+1;i<len;i++)
{
a2[i]='2';
}
for(int i=0;i<len;i++)
{
ans+=a2[i]-'0';
}
ans+=len;
printf("%d\n",max(ans1,ans));
}
}
int main()
{
int t;
cin >> t;
for(int i=1;i<=t;i++) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3532kb
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: -100
Wrong Answer
time: 4ms
memory: 3568kb
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:
wrong answer 200th numbers differ - expected: '3', found: '4'