QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630730 | #5117. Find Maximum | Eureka | WA | 1ms | 3616kb | C++14 | 1.6kb | 2024-10-11 20:09:45 | 2024-10-11 20:09:50 |
Judging History
answer
#include <bits/stdc++.h>
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 3e5 + 50;
const ll mod = 998244353;
//__builtin_ctzll(x);后导0的个数
//__builtin_popcount计算二进制中1的个数
void work() {
ll l, r; cin >> l >> r;
string tl = "", tr = "";
while (l || r) {
tr += '0' + (r % 3);
if (l) tl += '0' + (l % 3);
else tl += '0';
r /= 3; l /= 3;
}
reverse(tl.begin(), tl.end());
reverse(tr.begin(), tr.end());
int flag = -1, two = 0;
// if (tr == "11") {
// cout << "4\n"; return;
// }
for (int i = 0; i < tl.size() - 1; ++i) {
if (i == 0) {
if (tl[i] != tr[i] && tr[i] == '1') {
flag = 1;
}
}
if (!flag) {
if (tl[i] != tr[i]) {
flag = i;
}
} else {
if (flag == 1 && i <= 1) continue;
two += '2' - tr[i];
}
}
if (flag != -1 && two >= 1) {
tr[flag] --;
for (int i = flag + 1; i < tr.size(); ++i) {
tr[i] = '2';
}
}
// cout << tr << "\n" << tl << "\n";
ll ans = 0;
for (auto x: tr) {
if (!ans && x == '0') continue;
ans += x - '0' + 1;
}
cout << ans << '\n';
}
signed main() {
io;
int t = 1;
cin >> t;
while (t--) {
work();
}
return 0;
}
//131
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 1ms
memory: 3616kb
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 4 5 6 4 5 6 5 6 7 6 7 8 5 6 7 6 7 8 7 8 9 8 8 8 8 8 8 7 8 9 9 9 9 9 9 9 8 9 10 10 10 10 10 10 10 9 10 11 6 7 8 7 8 9 8 9 10 7 8 9 8 9 10 9 10 11 8 9 10 9 10 11 10 11 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 3 3 4 5 4 5 6 4 5 6 5 6 7 6 7 8 5 6 7 6 7 8 7 8 9 8 8 8 8 8 8...
result:
wrong answer 6th numbers differ - expected: '5', found: '4'