QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#702445 | #5981. Costly Binary Search | byron10000 | 27 ✓ | 11390ms | 86684kb | C++14 | 1.4kb | 2024-11-02 16:00:23 | 2024-11-02 16:00:23 |
Judging History
answer
#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define _UN using namespace
using namespace std;
const int MAXN=1e6+10;
int n,A[MAXN];
char tmp[MAXN];
int L[10][MAXN],R[10][MAXN];
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
// freopen("/dev/null","w",stderr);
#else
// freopen("cost.in","r",stdin);
// freopen("cost.out","w",stdout);
#endif
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int cas; cin>>cas;
RNG(_,1,cas){
cin>>(tmp+1),n=int(strlen(tmp+1));
RNG(i,1,n) A[i]=tmp[i]-'0';
RNG(x,0,n*9){
auto *pl=L[x%10],*pr=R[x%10];
fill_n(pl,n+2,n+1),fill_n(pr,n+2,0);
RNG(i,1,n){
if(A[i]>x) continue;
auto l=min(i,L[(x-A[i]+10)%10][i-1]),r=max(i,R[(x-A[i]+10)%10][i+1]);
pr[l]=max(pr[l],r),pl[r]=min(pl[r],l);
}
IRNG(i,n-1,1) pl[i]=min(pl[i],pl[i+1]);
RNG(i,2,n) pr[i]=max(pr[i],pr[i-1]);
if(pr[1]==n){ cout<<"Case #"<<_<<": "<<x<<"\n"; break; }
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 79ms
memory: 44620kb
input:
50 8 5128831164925953487661279378526736416489768154389124821528467927357884749642747626797857463132866343496157991453139582295398452863172464853698678624523849653538713928372648295734165346972222781179687541337591976277864785653638476127839556323849395641196246971351933655287441377531627938395427487...
output:
Case #1: 8 Case #2: 37 Case #3: 34 Case #4: 37 Case #5: 34 Case #6: 114 Case #7: 126 Case #8: 24 Case #9: 37 Case #10: 103 Case #11: 36 Case #12: 64 Case #13: 37 Case #14: 117 Case #15: 37 Case #16: 35 Case #17: 14 Case #18: 34 Case #19: 36 Case #20: 37 Case #21: 38 Case #22: 39 Case #23: 14 Case #2...
result:
ok 50 lines
Subtask #2:
score: 19
Accepted
Test #2:
score: 19
Accepted
time: 11390ms
memory: 86684kb
input:
50 647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...
output:
Case #1: 42 Case #2: 43 Case #3: 120 Case #4: 42 Case #5: 43 Case #6: 43 Case #7: 31 Case #8: 43 Case #9: 171 Case #10: 42 Case #11: 39 Case #12: 42 Case #13: 42 Case #14: 44 Case #15: 39 Case #16: 20 Case #17: 180 Case #18: 30 Case #19: 45 Case #20: 43 Case #21: 44 Case #22: 31 Case #23: 83 Case #2...
result:
ok 50 lines
Extra Test:
score: 0
Extra Test Passed