QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#428487#8769. Champernowne Substringucup-team135#TL 2811ms9492kbPython33.9kb2024-06-01 19:49:032024-06-01 19:49:03

Judging History

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

  • [2024-06-01 19:49:03]
  • 评测
  • 测评结果:TL
  • 用时:2811ms
  • 内存:9492kb
  • [2024-06-01 19:49:03]
  • 提交

answer

import math
def main():
    p=998244353
    t=int(input())
    for i in range(t):
        ch2=10**40
        res=10**40
        s=str(input())
        while(ord(s[len(s)-1])-ord('0')>9 or ord(s[len(s)-1])-ord('0')<0):
            s=s[0:len(s)-1:1]
        B=len(s)
        def get(ch):
            val=int(ch)
            l=len(ch)
            res1=(val-10**(l-1))*l
            for i in range(l-1):
                res1+=(9*(10**i))*(i+1)
            return res1
        def check(ch,pos,ch1):
            if(ch[0]=='0'):
                return 10**40
            val=int(ch)
            if(val>ch1):
                 return
            s1=str()
            while(len(s1)<pos+len(s)):
                s1+=str(val)
                val+=1
            to=s1[pos:pos+len(s):1]
            assert(len(s)==len(to))
            for i in range(len(s)):
                if(s[i]==to[i] or s[i]=='?'):
                    pass
                else:
                    return 10**40
            ch1=ch
            return get(ch)+pos+1
        for k in range(B+1):
            for x in range(11):
                for l in range(27//max(k,1)):
                        num=0
                        num=x*(10**k)-l
                        if(x==10 and k==0 and l==3):
                            pass
                                #print(num)
                        if(num>=1 and len(str(num))<=k+1):
                            if(x==1 and k==0 and l==3):
                                pass
                                #print(num)
                            for a in range(B+1):
                                if(a+k+1<=B+1):
                                    ch=str()
                                    if(a>=1):
                                        ch+='1'
                                        for i in range(a-1):
                                            ch+='0'
                                    le=k+1-len(str(num))
                                    for i in range(le):
                                       ch+='0'
                                    ch+=str(num)
                                    was=False
                                    if(a==0 and x==10 and k==0 and l==3):
                                        pass
                                        #print(ch)
                                    if(ch=="10003"):
                                        was=False
                                    ch1=ch
                                    assert(len(ch)==a+k+1)
                                    for pos in range(a+k+1):
                                        ch=ch1
                                        for i in range(len(s)):
                                            if(was):
                                                print(a)
                                            j=(pos+i)%(a+k+1)
                                            if(j<a):
                                                if(s[i]!='?'):
                                                    if(was):
                                                        print(i)
                                                    if(s[i]>ch[j]):
                                                        if(was and pos==4):
                                                            print(i,s[i],j)
                                                        ch=ch[0:j:1]+s[i]+ch[j+1:len(ch):1]
                                        if(was and pos==4):
                                            print(ch)
                                        answ=10**40
                                        if(s[0]=='?' or ch[pos]==s[0]):
                                            answ=check(ch,pos,ch2)
                                        if(answ<res):
                                           res=answ
                                           ch1=ch
        print(res%p)
main()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2811ms
memory: 9492kb

input:

9
0
???1
121
1?1?1
??5?54?50?5?505?65?5
000000000000
?2222222
?3????????9??8???????1??0
9?9??0????????????2

output:

11
7
14
10
314159
796889014
7777
8058869
38886

result:

ok 9 lines

Test #2:

score: -100
Time Limit Exceeded

input:

10
0000000000000000000000000
0000000?002100000000000?0
6999?999?999999989?999999
0???0?1000?0??000?????0?1
9??9?999998?9?999999100?0
96?9997999?8999991????010
99?99??999999999??????99?
?0?0000?00000000?0210?0?0
99?999?999?99?9??999?9?9?
9?????9?99?99??9??99??9??

output:

545305036
574985081
788888865
5889591
485490491
488873
902034054
830780534

result: