結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー rlangevin
提出日時 2023-10-19 21:14:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,179 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,108 KB
実行使用メモリ 78,732 KB
最終ジャッジ日時 2024-09-19 17:17:32
合計ジャッジ時間 8,954 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 13
権限があれば一括ダウンロードができます

ソースコード

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] + 1)
    
    L = []
    while N:
        if N >= M * M:
            if dp[N] == dp[N - M * M] + 1:
                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