結果

問題 No.1953 8
ユーザー jensenjensen
提出日時 2022-06-28 12:50:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 2,218 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-05-01 03:55:11
合計ジャッジ時間 5,214 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,136 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 29 ms
11,008 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 30 ms
11,008 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 30 ms
11,008 KB
testcase_07 AC 30 ms
11,008 KB
testcase_08 AC 30 ms
11,008 KB
testcase_09 AC 31 ms
11,008 KB
testcase_10 AC 30 ms
11,008 KB
testcase_11 AC 30 ms
11,008 KB
testcase_12 AC 29 ms
11,136 KB
testcase_13 AC 29 ms
11,008 KB
testcase_14 AC 30 ms
11,008 KB
testcase_15 AC 30 ms
11,008 KB
testcase_16 AC 29 ms
11,008 KB
testcase_17 AC 30 ms
11,008 KB
testcase_18 AC 29 ms
11,008 KB
testcase_19 AC 30 ms
11,008 KB
testcase_20 AC 30 ms
11,008 KB
testcase_21 AC 30 ms
11,136 KB
testcase_22 AC 29 ms
11,008 KB
testcase_23 AC 29 ms
11,136 KB
testcase_24 AC 29 ms
11,008 KB
testcase_25 AC 30 ms
11,008 KB
testcase_26 AC 30 ms
11,008 KB
testcase_27 AC 30 ms
11,008 KB
testcase_28 AC 30 ms
11,008 KB
testcase_29 AC 30 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

k=int(input())

i=0
n=1
m=1
ans=[]

while True:
    i+=54*10**(n-2)*(n-1)+10**(n-1)*5
    if i>=k: 
        i-=54*10**(n-2)*(n-1)+10**(n-1)*5
        i=int(i)
        break
    n+=1
#iにはn-1桁までの累計、nは答えの桁数    





def func(lis,n,l,i,k):
    m=0
    x=lis.count(4)+lis.count(6)+lis.count(8)*2+lis.count(9)+lis.count(0)
    while True:
        i+=(n-l-1)*6*10**(n-l-2)+x*10**(n-l-1)
            
        if m==0 or m==4 or m==6 or m== 9:
            i+=10**(n-l-1)
            if i>=k:
                i-=10**(n-l-1)+(n-l-1)*6*10**(n-l-2)+x*10**(n-l-1)
                break
        
        if m==8:
            i+=2*10**(n-l-1)
            if i>=k:
                i-=(n-l-1)*6*10**(n-l-2)+x*10**(n-l-1)+2*10**(n-l-1)
                break
                
        if i>=k:
            i-=(n-l-1)*6*10**(n-l-2)+x*10**(n-l-1)
            break
        m+=1
    return m,int(i)

def func2(lis,i,k):
    boo=False
    m=0
    x=lis.count(4)+lis.count(6)+lis.count(8)*2+lis.count(9)+lis.count(0)
    while m<10:
        i+=x
            
        if m==0 or m==4 or m==6 or m== 9:
            i+=1
            if i==k: 
                boo=True
                break
        if m==8:
            i+=2
            if i==k:
                boo=True
                break
        if i==k:
            boo=True
            break
        m+=1
    return m,boo


            
if n==1:
    m,boo=func2([],0,k+1)
    ans.append(m)
else:
    while m<10:
        i+=(n-1)*10**(n-2)*6
        if i>=k: 
            i-=(n-1)*10**(n-2)*6
            break
        
        if m==4 or m==6 or m==9:
            i+=10**(n-1)
            if i>=k:
                i-=10**(n-1)+(n-1)*10**(n-2)*6
                break
        elif m==8:
            i+=2*10**(n-1)
            if i>=k: 
                i-=2*10**(n-1)+(n-1)*10**(n-2)*6
                break
        m+=1  
    #mはn桁目の数字、iはn桁目が1~m-1までの累計
    
    ans.append(m)
    for l in range(n-2):
        m,i=func(ans,n,l+1,i,k)
        ans.append(m)
    m,boo=func2(ans,i,k)
    ans.append(m)

if boo==False: print(-1)
elif k==0: print(1)
else:
    t=0
    for i in range(len(ans)):
        t+=ans[i]*10**(n-i-1)
    print(t)
0