結果

問題 No.1633 Sorting Integers (Multiple of 2^K)
ユーザー googol_S0googol_S0
提出日時 2021-07-30 21:41:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,564 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 277,208 KB
最終ジャッジ日時 2023-10-14 03:59:39
合計ジャッジ時間 26,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,608 KB
testcase_01 AC 85 ms
75,608 KB
testcase_02 AC 183 ms
79,120 KB
testcase_03 AC 76 ms
71,324 KB
testcase_04 AC 77 ms
71,108 KB
testcase_05 AC 74 ms
71,364 KB
testcase_06 AC 81 ms
76,112 KB
testcase_07 AC 76 ms
71,440 KB
testcase_08 AC 75 ms
71,120 KB
testcase_09 AC 74 ms
71,452 KB
testcase_10 AC 73 ms
71,108 KB
testcase_11 AC 73 ms
71,320 KB
testcase_12 AC 76 ms
71,360 KB
testcase_13 AC 74 ms
71,404 KB
testcase_14 AC 74 ms
71,208 KB
testcase_15 AC 74 ms
71,572 KB
testcase_16 AC 76 ms
71,108 KB
testcase_17 AC 75 ms
71,284 KB
testcase_18 AC 74 ms
71,240 KB
testcase_19 AC 80 ms
76,088 KB
testcase_20 AC 82 ms
75,960 KB
testcase_21 AC 73 ms
71,520 KB
testcase_22 AC 81 ms
75,612 KB
testcase_23 AC 1,547 ms
274,760 KB
testcase_24 AC 1,486 ms
273,316 KB
testcase_25 AC 1,344 ms
277,208 KB
testcase_26 AC 1,353 ms
273,116 KB
testcase_27 AC 1,479 ms
276,392 KB
testcase_28 AC 1,360 ms
275,640 KB
testcase_29 AC 1,356 ms
276,436 KB
testcase_30 AC 1,355 ms
276,168 KB
testcase_31 AC 1,564 ms
272,988 KB
testcase_32 AC 1,417 ms
272,620 KB
testcase_33 AC 455 ms
119,620 KB
testcase_34 AC 237 ms
80,888 KB
testcase_35 AC 326 ms
97,760 KB
testcase_36 AC 274 ms
86,128 KB
testcase_37 AC 671 ms
176,544 KB
testcase_38 AC 930 ms
223,552 KB
testcase_39 AC 316 ms
90,484 KB
testcase_40 AC 244 ms
81,364 KB
testcase_41 AC 754 ms
194,744 KB
testcase_42 AC 243 ms
82,024 KB
testcase_43 AC 480 ms
122,260 KB
testcase_44 AC 1,089 ms
272,324 KB
testcase_45 AC 559 ms
142,824 KB
testcase_46 AC 267 ms
84,200 KB
testcase_47 AC 344 ms
92,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
C=list(map(int,input().split()))
A=[]
for i in range(9):
  for j in range(C[i]):
    A.append(i+1)
ANS=0
M=(N+1)>>1
L=N>>1
t=0
for u in range(5,-1,-1):
  t+=(1<<u)
  mod=1<<t
  P=[pow(10,i,mod) for i in range(N+1)]
  DP=[set() for i in range(1<<N)]
  DP[0]=set([0])
  for i in range(1<<N):
    c=bin(i).count('1')
    if c>=M:
      continue
    for j in range(N):
      if (i>>j)&1:
        continue
      if j>0 and A[j-1]==A[j] and (i>>(j-1))&1==0:
        continue
      for k in DP[i]:
        DP[i|(1<<j)].add((k*10+A[j])%mod)
  for i in range(1<<N):
    c=bin(i).count('1')
    if c>=L:
      x=((1<<N)-1)^i
      y=[0]*10
      for j in range(9):
        y[j+1]=y[j]+C[j]
      z=0
      p=0
      for k in range(N):
        while y[p]==k:
          p+=1
        if (x>>k)&1:
          z|=(1<<y[p-1])
          y[p-1]+=1
      x=z
      if len(DP[x])>0 and len(DP[i])>0:
        for j in DP[i]:
          if (-j*P[N-c])%mod in DP[x]:
            ANS=t
            break
        if ANS==t:
          break
  if ANS<t:
    t-=(1<<u)
print(ANS)
0