結果

問題 No.1376 Simple LPS Problem
ユーザー gew1fw
提出日時 2025-06-12 21:44:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,365 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 81,992 KB
実行使用メモリ 67,708 KB
最終ジャッジ日時 2025-06-12 21:49:04
合計ジャッジ時間 8,891 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    import sys
    N, K = map(int, sys.stdin.readline().split())
    
    if K == 1:
        s = []
        for i in range(N):
            s.append('0' if i % 2 == 0 else '1')
        print(''.join(s))
        return
    elif K == 2:
        s = ['0', '0']
        for i in range(2, N):
            s.append('1' if (i - 2) % 2 == 0 else '0')
        print(''.join(s))
        return
    else:
        if K % 2 == 1:
            if N > 2 * K - 1:
                print(-1)
                return
        
        s = []
        if K % 2 == 0:
            mid = K // 2
            for i in range(mid):
                s.append('0' if i % 2 == 0 else '1')
            for i in range(mid - 1, -1, -1):
                s.append(s[i])
        else:
            mid = (K + 1) // 2
            for i in range(mid):
                s.append('0' if i % 2 == 0 else '1')
            for i in range(mid - 2, -1, -1):
                s.append(s[i])
        
        last_char = s[-1] if s else '0'
        for i in range(K, N):
            pos_in_pal = 2 * K - 1 - i
            if pos_in_pal >= 0:
                current = s[pos_in_pal]
                s.append('1' if current == '0' else '0')
            else:
                s.append('1' if last_char == '0' else '0')
                last_char = s[-1]
        
        print(''.join(s))
        return

solve()
0