QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129198#6522. Digit Modethenegotiator1WA 482ms51276kbPython32.1kb2023-07-22 05:38:172023-07-22 05:38:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 05:38:20]
  • 评测
  • 测评结果:WA
  • 用时:482ms
  • 内存:51276kb
  • [2023-07-22 05:38:17]
  • 提交

answer


save=[]
def Digit_Mode(n):
    if len(save)>=n:
        return save[n-1]
    dp=[1,0,0,0,0,0,0,0,0,0]## first 10 for the digits and last mymax for the max occurance and the dp[11] id the number of 9's from the right 
    mymax=0
    sol=0
    lastdig=0
    for i in range(1,n+1):
        
        
        if lastdig==10:
            lastdig=0
        if lastdig!=9:
            dp[lastdig]-=1
            dp[lastdig+1]+=1
            if lastdig == mymax:
                if dp[lastdig+1]>dp[mymax]:
                    mymax= lastdig+1
                else:
                    tempmax=0
                    for i in range(10):
                        if dp[i]>=tempmax:
                            tempmax=dp[i]
                            mymax=i

            else:
                if dp[lastdig+1]>dp[mymax]:
                    mymax= lastdig+1
                elif dp[lastdig+1]==dp[mymax]:
                    if mymax<lastdig+1:
                        mymax=lastdig+1
                                       
        else: # if last dig 9
            x=i-1
            count=0
            lda9=None
            
            while True:
                temp=x%10
                
                if temp==9:
                    count+=1
                    x//=10
                else:
                    lda9=temp
                    break
          
            if x!=0:
                dp[9]-=count
                dp[0]+=count
                dp[lda9+1]+=1
                dp[lda9]-=1
            else:
                dp[9]-=count
                dp[0]+=count
                dp[lda9+1]+=1
            lda9+=1

            tempmax=0
            for i in range(10):
                if dp[i]>=tempmax:
                    tempmax=dp[i]
                    mymax=i

                
        sol+=mymax
        save.append(sol)
        lastdig+=1
       
    return sol

t = int(input())
for i in range(t):
    n = int(input())
    print(Digit_Mode(n))     


                    
        

                

            


            






  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 482ms
memory: 51276kb

input:

5
9
99
999
99999
999999

output:

45
615
6570
597600
5689830

result:

ok 5 number(s): "45 615 6570 597600 5689830"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 8148kb

input:

34
7
48
8
76
1
97
7
5
7
7
2
89
9
4
84
46
6
73
86
78
5
3
8
9
31
24
78
7
11
45
2
65
88
6

output:

28
236
1
420
1
202
28
15
28
28
3
155
3
10
139
190
21
82
145
100
15
6
1
3
104
74
100
28
10
181
3
46
151
21

result:

wrong answer 3rd numbers differ - expected: '36', found: '1'