結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 484 ms
81,884 KB
testcase_02 AC 478 ms
81,808 KB
testcase_03 AC 477 ms
81,772 KB
testcase_04 AC 474 ms
81,640 KB
testcase_05 AC 475 ms
81,800 KB
testcase_06 AC 475 ms
81,464 KB
testcase_07 AC 479 ms
82,056 KB
testcase_08 AC 485 ms
81,872 KB
testcase_09 AC 479 ms
82,108 KB
testcase_10 AC 473 ms
81,816 KB
testcase_11 AC 477 ms
81,684 KB
testcase_12 AC 481 ms
81,772 KB
testcase_13 AC 481 ms
81,780 KB
testcase_14 AC 479 ms
81,692 KB
testcase_15 AC 476 ms
81,540 KB
testcase_16 AC 476 ms
81,644 KB
testcase_17 AC 510 ms
81,984 KB
testcase_18 AC 483 ms
82,004 KB
testcase_19 AC 481 ms
82,052 KB
testcase_20 AC 479 ms
81,788 KB
testcase_21 AC 481 ms
81,800 KB
testcase_22 AC 476 ms
82,080 KB
testcase_23 AC 478 ms
81,868 KB
testcase_24 AC 480 ms
81,788 KB
testcase_25 AC 482 ms
82,000 KB
testcase_26 AC 479 ms
81,644 KB
testcase_27 AC 480 ms
81,844 KB
testcase_28 AC 482 ms
81,536 KB
testcase_29 AC 481 ms
81,792 KB
testcase_30 AC 477 ms
81,700 KB
testcase_31 AC 476 ms
81,692 KB
testcase_32 AC 481 ms
81,980 KB
testcase_33 AC 479 ms
81,832 KB
testcase_34 AC 481 ms
81,844 KB
testcase_35 AC 477 ms
81,512 KB
testcase_36 AC 479 ms
82,060 KB
testcase_37 AC 476 ms
81,460 KB
testcase_38 AC 477 ms
82,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
U = 3 * 10 ** 5
Usq = int(U ** 0.5 + 0.5)
sq = [i*i for i in range(Usq)]

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