QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556067#5981. Costly Binary Searchxcyyyyy8 1085ms86764kbC++201.3kb2024-09-10 14:47:442024-09-10 14:47:44

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 14:47:44]
  • 评测
  • 测评结果:8
  • 用时:1085ms
  • 内存:86764kb
  • [2024-09-10 14:47:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define id(x) (x+10)%10
char s[N];int c[N];
int n,L[10][N],R[10][N];
vector<int> ll[N],rr[N];
void work(int cs){
    scanf("%s",s+1);n=strlen(s+1);
    for(int i=1;i<=n;i++)c[i]=s[i]-'0';
    memset(L,0x3f,sizeof L);
    memset(R,-0x3f,sizeof R);
    for(int w=1;w<=180;w++){
        for(int i=1;i<=n;i++){
            L[id(w)][i]=L[id(w-1)][i],R[id(w)][i]=R[id(w-1)][i];
            if(w==c[i])L[id(w)][i]=R[id(w)][i]=i;
            vector<int>().swap(ll[i]),vector<int>().swap(rr[i]);
        }
        for(int i=1;i<=n;i++)if(c[i]<=w){
            int l=i==1?1:L[id(w-c[i])][i-1],r=i==n?n:R[id(w-c[i])][i+1];
            if(l<=r)ll[l].push_back(r),rr[r].push_back(l);
        }
        int mx=-0x3f3f3f3f,mn=0x3f3f3f3f;
        for(int i=1;i<=n;i++){
            for(int x:ll[i])mx=max(mx,x);
            R[id(w)][i]=max(R[id(w)][i],mx);
        }
        for(int i=n;i;i--){
            for(int x:rr[i])mn=min(mn,x);
            L[id(w)][i]=min(L[id(w)][i],mn);
        }
        if(R[id(w)][1]==n)return printf("Case #%d: %d\n",cs,w),void();
    }
    puts("No Answer!");
}
int main(){
    int t;scanf("%d",&t);
    for(int i=1;i<=t;i++)work(i);
}
/*
4
111
1111
1111111
1111119

Case #1: 2
Case #2: 3
Case #3: 3
Case #4: 10
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 1085ms
memory: 86764kb

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: 0
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

input:

50
647322722753778843259213887674615134214258235986992692879314555957455541351526284343217116351733247781713552149464672262787737941588358671583528664757823365936975517145283412965139791726299864122725212222496898855627124979178341548651669956711341742838725446489235961853391195148929571712449139335...

output:


result: