QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722555 | #5117. Find Maximum | TANGTANGCC | WA | 2ms | 3748kb | C++14 | 1.6kb | 2024-11-07 19:31:28 | 2024-11-07 19:31:31 |
Judging History
answer
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define i32 int
#define u32 unsigned int
#define i64 long long
#define u64 unsigned long long
#define u27 __int128
#define endl '\n'
#define VI vector<int>
#define VVI vector<VI>
#define rand() RANDOM(GEN)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define CTM (cout<<"Time:"<<static_cast<double>(clock()-START_TIME)/CLOCKS_PER_SEC*1000<<"ms"<<endl)
typedef long long ll;
using namespace std;
random_device SEED;
mt19937_64 GEN(SEED());
uniform_int_distribution<u64> RANDOM(0, numeric_limits<u64>::max());
const clock_t START_TIME = clock();
int a[50],b[50];
int calc(int l,int r) {
int x=l,y=r,nb=0;
for (int i = 0; i < 45; ++i) {
a[i]=l%3,b[i]=r%3;
l/=3,r/=3;
}
int ctb;
for (int i = 0; i <= 40; ++i) {
nb+=b[i];
if(b[i]) ctb=i;
}
nb=nb+ctb+1;
if(x==y) return nb;
int ans=0;
int pos;
int f=0,g;
for (int i = 40; i >= 0; --i) {
if(!f and b[i]) f=1,g=i;
pos=i;
if(a[i]!=b[i]) break;
if(f) ans+=a[i]+1;
}
if(b[pos]!=1 or g!=pos) ans+=b[pos];
for (int i = pos-1; i >= 0; --i) {
ans+=3;
}
return max({ans, nb});
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
IO;
int tt;
cin>>tt;
while(tt--) {
int l,r;
cin>>l>>r;
cout<<calc(l,r)<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
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: 2ms
memory: 3676kb
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 6 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 9 9 9 9 9 10 9 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 6 7 8 8 8 8 8 8 8 8 8 9...
result:
wrong answer 15th numbers differ - expected: '7', found: '6'