QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235570 | #5117. Find Maximum | He2717970784 | WA | 1ms | 3508kb | C++17 | 1.9kb | 2023-11-02 21:59:07 | 2023-11-02 21:59:07 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
vector<int>a, b;
void pre() {
a = b = vector<int>(9, 0);
for (int i = 0; i < 3; i++) {
a[i] = i + 1;
b[i] = i + 2;
}
for (int i = 3; i < 6; i++) {
a[i] = b[i] = i;
}
for (int i = 6; i < 9; i++) {
a[i] = b[i] = i - 2;
}
}
int solve() {
int l = 0, r = 0;
cin >> l >> r;
vector<int>R;
while (r >= 1) {
R.push_back(r % 3);
r /= 3;
}
reverse(R.begin(), R.end());
int n = R.size();
vector<int>L(n, 0);
for (int i = n - 1; l >= 1 && i >= 0; i--) {
L[i] = l % 3;
l /= 3;
}
int idx = 0, ans = 0;
while (idx < n) {
while (idx < n && L[idx] == R[idx]) {
ans += L[idx] + 1;
idx++;
}
if (idx < n - 2) {
vector<int>c;
for (int i = 0; i < idx; i++) {
c.push_back(R[i]);
}
c.push_back(R[idx] - 1);
for (int i = idx + 1; i < n; i++) {
c.push_back(2);
}
c[idx + 1] = c[idx];
c[idx]++;
bool flag = false;
for (int i = idx; i < n; i++) {
if (c[i] > R[i]) {
flag = true;
break;
}
}
if (flag) {
for (int i = idx; i < n; i++) {
ans += c[i] + 1;
}
break;
}
else {
L = c;
idx++;
}
}
else if (idx >= n) {
break;
}
else if (idx == n - 1) {
ans += R[idx] + 1;
break;
}
else if (idx == n - 2) {
int res = 0, u = L[idx] * 3 + L[idx + 1], v = R[idx] * 3 + R[idx + 1];
if (idx) {
for (int i = u; i <= v; i++) {
res = max(res, b[i]);
}
}
else {
for (int i = u; i <= v; i++) {
res = max(res, a[i]);
}
}
ans += res;
break;
}
}
return ans;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
pre();
int t = 0;
cin >> t;
while (t--) {
int ans = solve();
cout << ans << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3508kb
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: 0ms
memory: 3484kb
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 4 6 6 5 6 6 6 8 8 8 8 8 5 8 8 6 9 9 9 9 9 9 9 9 7 9 9 9 9 9 9 9 9 6 9 9 9 9 9 9 9 9 6 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 8 11 11 11 11 11 11 11 11 6 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 4 6 6 5 6 6 6 8 8 8 8 8 5 8 8 6 9 9 9...
result:
wrong answer 11th numbers differ - expected: '6', found: '4'