結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー rlangevinrlangevin
提出日時 2023-10-19 21:16:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,179 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 77,988 KB
最終ジャッジ日時 2023-10-19 21:17:07
合計ジャッジ時間 9,840 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 237 ms
73,148 KB
testcase_02 AC 943 ms
77,916 KB
testcase_03 WA -
testcase_04 AC 43 ms
55,860 KB
testcase_05 AC 42 ms
55,632 KB
testcase_06 AC 43 ms
55,860 KB
testcase_07 AC 43 ms
55,860 KB
testcase_08 AC 216 ms
73,076 KB
testcase_09 AC 43 ms
55,860 KB
testcase_10 AC 42 ms
55,860 KB
testcase_11 AC 42 ms
55,860 KB
testcase_12 AC 91 ms
66,456 KB
testcase_13 AC 42 ms
55,860 KB
testcase_14 AC 42 ms
55,860 KB
testcase_15 AC 42 ms
55,860 KB
testcase_16 AC 43 ms
55,860 KB
testcase_17 AC 42 ms
55,860 KB
testcase_18 AC 42 ms
55,860 KB
testcase_19 AC 41 ms
55,860 KB
testcase_20 AC 42 ms
55,860 KB
testcase_21 AC 43 ms
55,860 KB
testcase_22 AC 42 ms
55,860 KB
testcase_23 AC 42 ms
55,860 KB
testcase_24 AC 42 ms
55,860 KB
testcase_25 AC 42 ms
55,860 KB
testcase_26 AC 42 ms
55,860 KB
testcase_27 AC 43 ms
55,860 KB
testcase_28 AC 42 ms
55,860 KB
testcase_29 AC 45 ms
55,860 KB
testcase_30 AC 42 ms
55,860 KB
testcase_31 AC 42 ms
55,860 KB
testcase_32 AC 69 ms
64,284 KB
testcase_33 AC 59 ms
72,568 KB
testcase_34 AC 149 ms
70,804 KB
testcase_35 AC 983 ms
77,988 KB
testcase_36 AC 494 ms
77,140 KB
testcase_37 AC 977 ms
77,988 KB
testcase_38 AC 946 ms
77,988 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 = []
    while N:
        if N >= M * M:
            if dp[N] == dp[N - M * M] + M:
                N -= M * M
                L.append(M)
                continue
        M -= 1

    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