QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#712338 | #5981. Costly Binary Search | Lu_xZ | 0 | 0ms | 0kb | C++20 | 1.0kb | 2024-11-05 15:22:44 | 2024-11-05 15:22:47 |
answer
#include<bits/stdc++.h>
#define eb emplace_back
#define ep emplace
using namespace std;
using ll = long long;
constexpr int N = 1e6 + 5;
int n, L[10][N], R[10][N];
char w[N];
void solve(int Case) {
scanf("%s", w + 1);
n = strlen(w + 1);
for(int i = 1; i <= n; ++ i) {
w[i] -= '0';
}
int ans = 0, k = 0, t;
while(1) {
for(int i = 0; i <= n + 1; ++ i) L[k][i] = i - 1, R[k][i] = i + 1;
for(int i = 1, j, l, r; i <= n; ++ i) {
if(ans >= w[i]) {
j = (ans - w[i]) % 10, l = L[j][i], r = R[j][i];
L[k][r] = min(L[k][r], l);
R[k][l] = max(R[k][l], r);
}
}
for(int i = n; i >= 0; -- i) L[k][i] = min(L[k][i], L[k][i + 1]);
for(int i = 1; i <= n + 1; ++ i) R[i][k] = max(R[k][i], R[k][i - 1]);
if(R[k][0] > n && L[k][n + 1] < 1) break;
t = k, ++ ans;
if(++ k == 10) k = 0;
memcpy(L[k], L[t], n + 1 << 2);
memcpy(R[k], R[t], n + 1 << 2);
}
printf("Case #%d: %d\n", Case, ans);
}
int main() {
int T; scanf("%d", &T);
for(int i = 1; i <= T; ++ i) solve(i);
return 0;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...