結果
問題 |
No.2247 01 ZigZag
|
ユーザー |
|
提出日時 | 2023-03-24 22:16:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,666 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 80,148 KB |
最終ジャッジ日時 | 2024-09-18 17:13:47 |
合計ジャッジ時間 | 4,647 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 50 |
ソースコード
import sys from collections import deque input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) INF = 2**63-1 mod = 998244353 n, m, k = mi() ans = '2' #0101...型 s1 = deque(['0']) cnt0 = 1 cnt1 = 0 for i in range(k): if i % 2 == 0: cnt1 += 1 s1.append('1') else: cnt0 += 1 s1.append('0') if cnt0 <= n and cnt1 <= m: while cnt0 < n: if s1 and s1[0] == '1': t = s1.popleft() s1.appendleft('0') s1.appendleft(t) else: s1.appendleft('0') cnt0 += 1 while cnt1 < m: if s1 and s1[-1] == '0': t = s1.pop() s1.append('1') s1.append(t) else: s1.append('1') cnt1 += 1 ans = min(ans, ''.join(s1)) #1010...型 s1 = deque(['1']) cnt0 = 0 cnt1 = 1 for i in range(k): if i % 2: cnt1 += 1 s1.append('1') else: cnt0 += 1 s1.append('0') if cnt0 <= n and cnt1 <= m: while cnt0 < n: if s1 and s1[0] == '1': t = s1.popleft() s1.appendleft('0') s1.appendleft(t) else: s1.appendleft('0') cnt0 += 1 while cnt1 < m: if s1 and s1[-1] == '0': t = s1.pop() s1.append('1') s1.append(t) else: s1.append('1') cnt1 += 1 ans = min(ans, ''.join(s1)) if ans == '2': print(-1) else: cnt = 0 for i in range(len(ans) - 1): if ans[i] != ans[i + 1]: cnt += 1 print(ans if cnt == k else -1)