結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー rlangevinrlangevin
提出日時 2023-10-19 21:21:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,151 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 78,024 KB
最終ジャッジ日時 2023-10-19 21:21:16
合計ジャッジ時間 11,130 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 526 ms
77,032 KB
testcase_01 AC 267 ms
73,180 KB
testcase_02 AC 1,112 ms
77,952 KB
testcase_03 AC 825 ms
77,664 KB
testcase_04 AC 44 ms
55,900 KB
testcase_05 AC 43 ms
55,672 KB
testcase_06 AC 43 ms
55,900 KB
testcase_07 AC 48 ms
55,900 KB
testcase_08 AC 238 ms
73,108 KB
testcase_09 AC 43 ms
55,900 KB
testcase_10 AC 43 ms
55,900 KB
testcase_11 AC 44 ms
55,900 KB
testcase_12 AC 97 ms
66,488 KB
testcase_13 AC 44 ms
55,900 KB
testcase_14 AC 43 ms
55,900 KB
testcase_15 AC 43 ms
55,900 KB
testcase_16 AC 43 ms
55,900 KB
testcase_17 AC 43 ms
55,900 KB
testcase_18 AC 44 ms
55,900 KB
testcase_19 AC 43 ms
55,900 KB
testcase_20 AC 43 ms
55,900 KB
testcase_21 AC 43 ms
55,900 KB
testcase_22 AC 44 ms
55,900 KB
testcase_23 AC 44 ms
55,900 KB
testcase_24 AC 46 ms
55,900 KB
testcase_25 AC 45 ms
55,900 KB
testcase_26 AC 43 ms
55,900 KB
testcase_27 AC 45 ms
55,900 KB
testcase_28 AC 44 ms
55,900 KB
testcase_29 AC 44 ms
55,900 KB
testcase_30 AC 43 ms
55,900 KB
testcase_31 AC 44 ms
55,900 KB
testcase_32 AC 73 ms
64,316 KB
testcase_33 AC 60 ms
72,668 KB
testcase_34 AC 166 ms
70,836 KB
testcase_35 AC 1,151 ms
78,024 KB
testcase_36 AC 557 ms
77,180 KB
testcase_37 AC 1,112 ms
78,024 KB
testcase_38 AC 1,132 ms
78,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

def main():
    N = int(input())
    M = int(N ** 0.5) + 2
    inf = 10 ** 18
    dp = [inf] * (N + 1)
    dp[0] = 0
    for i in range(N):
        for j in range(1, M + 1):
            nex = i + j * j
            if i + j * j > N:
                break
            dp[nex] = min(dp[nex], dp[i] + j)
    
    L = []
    now = N
    for i in range(1, M, 2):
        while now >= i * i:
            if dp[now] == dp[now - i * i] + i:
                now -= i * i
                L.append(i)
                continue
            else:
                break
    for i in range(2, M, 2):
        while now >= i * i:
            if dp[now] == dp[now - i * i] + i:
                now -= i * i
                L.append(i)
                continue
            else:
                break

    def f(t):
        odd, even = [], []
        for i in range(len(t)):
            if t[i] % 2:
                odd.append(t[i])
            else:
                even.append(t[i])
        odd.sort()
        even.sort()
        even = deque(even)
        cnt = 0
        while even:
            if cnt % 2:
                odd.append(even.popleft())
            else:
                odd.append(even.pop())
            cnt += 1
        lst = []
        now = 0
        for a in odd:
            for i in range(a):
                lst.append(str(now))
                now = 1 - now
            now = 1 - now
        return "".join(lst)

    print(f(L))

main()
0