QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129189 | #6522. Digit Mode | thenegotiator1 | TL | 1239ms | 8232kb | Python3 | 2.0kb | 2023-07-22 05:16:32 | 2023-07-22 05:16:35 |
Judging History
answer
def Digit_Mode(n):
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
lastdig+=1
return sol
t = int(input())
for i in range(t):
n = int(input())
print(Digit_Mode(n))
详细
Test #1:
score: 100
Accepted
time: 426ms
memory: 8144kb
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: 0
Accepted
time: 14ms
memory: 8212kb
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 36 420 1 597 28 15 28 28 3 525 45 10 484 221 21 399 500 435 15 6 36 45 145 104 435 28 47 215 3 341 516 21
result:
ok 34 numbers
Test #3:
score: 0
Accepted
time: 9ms
memory: 8132kb
input:
16 935 888 429 370 499 881 285 162 178 948 205 858 573 249 773 615
output:
6009 5618 2456 2078 2905 5562 1603 887 993 6121 1174 5378 3333 1374 4724 3631
result:
ok 16 numbers
Test #4:
score: 0
Accepted
time: 36ms
memory: 8232kb
input:
12 1242 9985 6469 9310 4191 9497 3166 3495 9711 9698 4137 2257
output:
7292 63531 37910 58047 23987 59479 18076 19675 61184 61086 23672 12913
result:
ok 12 numbers
Test #5:
score: 0
Accepted
time: 191ms
memory: 8144kb
input:
10 61195 72739 10164 79164 57851 12326 29132 55992 67377 13873
output:
337575 408170 63792 450686 316513 70493 157773 305011 374163 77954
result:
ok 10 numbers
Test #6:
score: 0
Accepted
time: 1239ms
memory: 8204kb
input:
8 529983 127270 421121 291729 461233 695056 365028 271160
output:
2744573 687141 2160067 1500426 2359204 3705475 1851172 1381981
result:
ok 8 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
7 7934351 8474057 1287369 5845624 7796773 5805755 7349121