QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#711938 | #5981. Costly Binary Search | Lu_xZ | 0 | 1530ms | 276268kb | C++20 | 1.3kb | 2024-11-05 14:02:43 | 2024-11-05 14:02:44 |
Judging History
answer
#include<bits/stdc++.h>
#define eb emplace_back
#define ep emplace
using namespace std;
using ll = long long;
constexpr int N = 1e5 + 5, M = 70;
int n, f[N][M]; char w[N];
struct Fenwick {
int t[N];
void clear() {memset(t + 1, 0, n + 1 << 2);}
void update(int p, int v) {
if(!p) return;
while(p <= n) {t[p] = max(t[p], v), p += p & -p;}
}
int query(int p) {
int tmp = 0;
while(p >= 1) {tmp = max(t[p], tmp), p -= p & -p;}
return tmp;
}
} T[M][10];
void solve(int Case) {
scanf("%s", w + 1), n = strlen(w + 1);
for(int i = 1; i < M; ++ i) {
for(int j = 1; j <= 9; ++ j) T[i][j].clear();
}
for(int i = n; i; -- i) {
w[i] -= '0';
for(int v = 1; v < w[i]; ++ v) f[i][v] = 0;
for(int v = w[i]; v < M; ++ v) {
f[i][v] = i;
T[v][w[i]].update(i - 1, f[i + 1][v - w[i]]);
}
}
for(int l = n; l; -- l) {
for(int v = 1; v < M; ++ v) {
for(int w = 1; w <= min(v, 9); ++ w) {
f[l][v] = max(f[l][v], T[v][w].query(f[l][v - w]));
}
}
for(int v = w[l]; v < M; ++ v) {
T[v][w[l]].update(l - 1, f[l + 1][v - w[l]]);
}
}
for(int i = 1; i < M; ++ i) {
if(f[1][i] == n) return void(printf("Case #%d: %d\n", Case, i));
}
}
int main() {
int T; scanf("%d", &T);
for(int i = 1; i <= T; ++ i) solve(i);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1530ms
memory: 276268kb
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
Case #1: 8 Case #2: 37 Case #4: 37 Case #5: 34 Case #9: 37 Case #17: 14 Case #22: 39 Case #23: 14 Case #24: 9 Case #26: 37 Case #38: 1 Case #39: 3 Case #41: 30 Case #42: 37 Case #47: 14
result:
wrong answer 3rd lines differ - expected: 'Case #3: 34', found: 'Case #4: 37'
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...