結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 tatyamtatyam
提出日時 2019-07-11 01:57:18
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,594 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 84,056 KB
最終ジャッジ日時 2023-09-02 07:06:19
合計ジャッジ時間 16,835 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 752 ms
81,080 KB
testcase_01 AC 431 ms
79,424 KB
testcase_02 AC 1,531 ms
83,884 KB
testcase_03 AC 1,258 ms
82,896 KB
testcase_04 AC 71 ms
71,180 KB
testcase_05 AC 69 ms
71,240 KB
testcase_06 AC 68 ms
71,116 KB
testcase_07 AC 72 ms
71,316 KB
testcase_08 AC 392 ms
79,468 KB
testcase_09 AC 69 ms
71,076 KB
testcase_10 AC 69 ms
71,472 KB
testcase_11 AC 68 ms
71,320 KB
testcase_12 AC 173 ms
77,748 KB
testcase_13 AC 70 ms
70,944 KB
testcase_14 AC 69 ms
71,472 KB
testcase_15 AC 71 ms
71,128 KB
testcase_16 AC 67 ms
71,184 KB
testcase_17 AC 69 ms
71,072 KB
testcase_18 AC 70 ms
71,124 KB
testcase_19 AC 72 ms
71,188 KB
testcase_20 AC 73 ms
71,156 KB
testcase_21 AC 74 ms
71,432 KB
testcase_22 AC 72 ms
71,500 KB
testcase_23 AC 73 ms
71,264 KB
testcase_24 AC 74 ms
71,484 KB
testcase_25 AC 72 ms
71,072 KB
testcase_26 AC 73 ms
71,304 KB
testcase_27 AC 74 ms
71,288 KB
testcase_28 AC 72 ms
71,432 KB
testcase_29 AC 72 ms
71,108 KB
testcase_30 AC 74 ms
71,132 KB
testcase_31 AC 73 ms
71,052 KB
testcase_32 AC 139 ms
77,272 KB
testcase_33 AC 160 ms
77,016 KB
testcase_34 AC 283 ms
78,712 KB
testcase_35 AC 1,594 ms
84,056 KB
testcase_36 AC 866 ms
81,400 KB
testcase_37 AC 1,589 ms
83,940 KB
testcase_38 AC 1,589 ms
83,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 0x1fffffffffffffff

def priority(a):
    return a if a & 1 else INF - a

n = int(input())
dp = [INF] * (n + 1)
mn = [INF] * (n + 1)
mx = [-INF] * (n + 1)
dp[0] = 0
for i in range(n):
    j = 1
    while i + j * j <= n:
        if dp[i + j * j] > dp[i] + j:
            dp[i + j * j] = dp[i] + j
            mn[i + j * j] = j
            mx[i + j * j] = j
        
        elif(dp[i + j * j] == dp[i] + j):
            if priority(mn[i + j * j]) > priority(j):
                mn[i + j * j] = j
            
            if priority(mx[i + j * j]) < priority(j):
                mx[i + j * j] = j
        j += 1
c = 48
ans = ""
while n:
    cnt = mn[n] if c == 48 else mx[n]
    n -= cnt * cnt;
    for i in range(cnt):
        ans += chr(c)
        c ^= 1
    
    c ^= 1;

print(ans)
0