結果
問題 | No.362 門松ナンバー |
ユーザー |
![]() |
提出日時 | 2023-02-03 02:04:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,505 bytes |
コンパイル時間 | 89 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 18,176 KB |
最終ジャッジ日時 | 2024-07-02 11:19:47 |
合計ジャッジ時間 | 48,964 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 TLE * 10 |
ソースコード
import sysreadline=sys.stdin.readlinedef Bisect_Int(ok,ng,is_ok):while abs(ok-ng)>1:mid=(ok+ng)//2if is_ok(mid):ok=midelse:ng=midreturn okdef check(a,b,c):if a==b:return Falseif a==c:return Falseif b==c:return Falsereturn 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]+=1cur=(N[0],N[1])for i in range(2,len(N)):n=N[i]prev=dpdp=[[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=curfor c in range(n):if check(a,b,c):dp[b][c]+=1if i!=len(N)-1:for a in range(1,10):for b in range(10):dp[a][b]+=1if cur!=None:a,b=curc=nif check(a,b,c):cur=(b,c)else:cur=Nonereturn 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)<Kans=Bisect_Int(101,1<<50,is_ok)print(ans)