結果

問題 No.110 しましまピラミッド
コンテスト
ユーザー kyotoku1483
提出日時 2025-11-04 21:50:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 786 bytes
コンパイル時間 1,230 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2025-11-04 21:50:45
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge7 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

nw = int(input())
w = sorted(list(map(int, input().split())), reverse=True)
nb = int(input())
b = sorted(list(map(int, input().split())), reverse=True)
blocks = []
for x in w:
    blocks.append((x, 0))
for x in b:
    blocks.append((x, 1))
blocks.sort(reverse=True)
cnt = 1
top = blocks[0][0]
color = blocks[0][1]
i = 1
while i < nw + nb:
    x, c = blocks[i]
    if x < top and c != color:
        top = x
        color ^= 1
        cnt += 1
    i += 1
ans = cnt
color = blocks[0][1]
i = 0
while i < nw + nb:
    _, c = blocks[i]
    if c != color:
        color ^= 1
        break
    i += 1
top = blocks[i][0]
cnt = 1
while i < nw + nb:
    x, c = blocks[i]
    if x < top and c != color:
        top = x
        color ^= 1
        cnt += 1
    i += 1
ans = max(ans, cnt)
print(ans)
0