結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-07 21:25:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,188 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 82,548 KB
最終ジャッジ日時 2023-09-17 20:29:37
合計ジャッジ時間 29,567 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 681 ms
82,080 KB
testcase_01 AC 682 ms
82,000 KB
testcase_02 AC 685 ms
82,036 KB
testcase_03 AC 685 ms
82,196 KB
testcase_04 AC 676 ms
81,900 KB
testcase_05 AC 685 ms
82,096 KB
testcase_06 AC 685 ms
82,196 KB
testcase_07 AC 685 ms
82,172 KB
testcase_08 AC 687 ms
82,008 KB
testcase_09 AC 682 ms
81,896 KB
testcase_10 AC 682 ms
82,208 KB
testcase_11 AC 684 ms
82,000 KB
testcase_12 AC 686 ms
81,840 KB
testcase_13 AC 679 ms
81,980 KB
testcase_14 AC 690 ms
82,236 KB
testcase_15 AC 687 ms
82,188 KB
testcase_16 AC 677 ms
81,972 KB
testcase_17 AC 687 ms
82,192 KB
testcase_18 AC 687 ms
82,192 KB
testcase_19 WA -
testcase_20 AC 688 ms
82,012 KB
testcase_21 AC 679 ms
82,112 KB
testcase_22 AC 679 ms
82,192 KB
testcase_23 AC 682 ms
82,036 KB
testcase_24 AC 688 ms
82,192 KB
testcase_25 AC 688 ms
82,072 KB
testcase_26 AC 685 ms
82,212 KB
testcase_27 AC 684 ms
82,004 KB
testcase_28 AC 688 ms
82,236 KB
testcase_29 AC 677 ms
82,000 KB
testcase_30 AC 673 ms
81,992 KB
testcase_31 AC 683 ms
82,352 KB
testcase_32 AC 676 ms
82,232 KB
testcase_33 AC 674 ms
82,172 KB
testcase_34 AC 688 ms
81,840 KB
testcase_35 AC 687 ms
81,880 KB
testcase_36 AC 680 ms
81,988 KB
testcase_37 WA -
testcase_38 AC 681 ms
82,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
U = 3 * 10 ** 5
Usq = int(U ** 0.5 + 0.5)
sq = [(i, i * i) for i in range(1, Usq)]
od = sq[0::2]
ev = sq[1::2]

dp = [U] * (U + 1)
prev = [-1] * (U + 1)  # p*pマス戻る、-1ならおわり
for i, s in sq:
    prev[s] = i
    dp[s] = i
    
for i in range(1, U + 1):
    for j, s in ev:
        if s > i:
            break
        if dp[i] >= dp[i - s] + j:
            dp[i] = dp[i - s] + j
            prev[i] = j
    for j, s in od:
        if s > i:
            break
        if dp[i] > dp[i - s] + j:
            dp[i] = dp[i - s] + j
            prev[i] = j

N = int(input())
seq = []
i = N
while i:
    p = prev[i]
    seq.append(p)
    i -= p * p

seq.sort()
odd = []
even = []
for s in seq:
    if s % 2 == 0:
        even.append(s)
    else:
        odd.append(s)

ans = []
for s in odd:
    bit = "".join(["0" if i % 2 == 0 else "1" for i in range(s)])
    ans.append(bit)

even = deque(even)
rev = 0
while even:
    if rev:
        s = even.popleft()
    else:
        s = even.pop()
    bit = "".join(["0" if i % 2 == 0 else "1" for i in range(s)])
    if rev:
        bit = bit[::-1]
    ans.append(bit)
    rev = 1 - rev

print("".join(ans))
0