結果

問題 No.362 門松ナンバー
ユーザー vwxyzvwxyz
提出日時 2023-02-03 02:04:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,505 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 8,240 KB
最終ジャッジ日時 2023-09-15 06:45:20
合計ジャッジ時間 47,931 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 857 ms
8,116 KB
testcase_01 AC 689 ms
8,204 KB
testcase_02 AC 688 ms
8,240 KB
testcase_03 AC 363 ms
8,112 KB
testcase_04 AC 197 ms
8,212 KB
testcase_05 AC 1,148 ms
8,096 KB
testcase_06 AC 2,094 ms
8,200 KB
testcase_07 AC 1,185 ms
8,060 KB
testcase_08 AC 1,610 ms
8,060 KB
testcase_09 AC 2,590 ms
8,060 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 2,868 ms
8,156 KB
testcase_18 TLE -
testcase_19 AC 1,700 ms
8,040 KB
testcase_20 TLE -
testcase_21 AC 352 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def Bisect_Int(ok,ng,is_ok):
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if is_ok(mid):
            ok=mid
        else:
            ng=mid
    return ok

def check(a,b,c):
    if a==b:
        return False
    if a==c:
        return False
    if b==c:
        return False
    return b in (max(a,b,c),min(a,b,c))

def solve(N):
    N=list(map(int,list(str(N))))
    dp=[[0]*10 for i in range(10)]
    for a in range(1,10):
        for b in range(10):
            if (a,b)<(N[0],N[1]):
                dp[a][b]+=1
    cur=(N[0],N[1])
    for i in range(2,len(N)):
        n=N[i]
        prev=dp
        dp=[[0]*10 for a in range(10)]
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    if check(a,b,c):
                        dp[b][c]+=prev[a][b]
        if cur!=None:
            a,b=cur
            for c in range(n):
                if check(a,b,c):
                    dp[b][c]+=1
        if i!=len(N)-1:
            for a in range(1,10):
                for b in range(10):
                    dp[a][b]+=1
        if cur!=None:
            a,b=cur
            c=n
            if check(a,b,c):
                cur=(b,c)
            else:
                cur=None
    return sum(dp[a][b] for a in range(10) for b in range(10))

T=int(readline())
for t in range(T):
    K=int(readline())
    def is_ok(ans):
        return solve(ans)<K
    ans=Bisect_Int(101,1<<50,is_ok)
    print(ans)
0