結果
問題 |
No.1376 Simple LPS Problem
|
ユーザー |
![]() |
提出日時 | 2025-04-09 21:05:14 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,104 bytes |
コンパイル時間 | 394 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 54,200 KB |
最終ジャッジ日時 | 2025-04-09 21:06:57 |
合計ジャッジ時間 | 7,922 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 WA * 22 |
ソースコード
N, K = map(int, input().split()) def solve(N, K): if K == 1: return '0' if N == 1 else -1 if K == N: return '0' * N if K > N or K < 1: return -1 # Even K if K % 2 == 0: half = K // 2 first_half = '0' * (half - 1) + '1' palindrome = first_half + first_half[::-1] remaining = N - K if remaining > 0: next_char = '1' if palindrome[-1] == '0' else '0' suffix = next_char + '0' * (remaining - 1) result = palindrome + suffix else: result = palindrome return result # Odd K else: if N > 2 * K - 1: return -1 mid = (K + 1) // 2 palindrome = '0' * (mid - 1) + '1' + '0' * (mid - 1) remaining = N - K if remaining > 0: next_char = '0' if palindrome[-1] == '1' else '1' suffix = next_char + '0' * (remaining - 1) result = palindrome + suffix else: result = palindrome return result result = solve(N, K) print(result if result != -1 else -1)