結果

問題 No.110 しましまピラミッド
ユーザー kichirb3kichirb3
提出日時 2018-03-21 17:48:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,412 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-08-30 04:02:50
合計ジャッジ時間 2,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,316 KB
testcase_01 AC 17 ms
8,220 KB
testcase_02 AC 17 ms
8,228 KB
testcase_03 AC 17 ms
8,244 KB
testcase_04 AC 16 ms
8,204 KB
testcase_05 AC 17 ms
8,376 KB
testcase_06 AC 17 ms
8,212 KB
testcase_07 AC 17 ms
8,240 KB
testcase_08 AC 17 ms
8,228 KB
testcase_09 AC 17 ms
8,148 KB
testcase_10 AC 17 ms
8,204 KB
testcase_11 AC 17 ms
8,324 KB
testcase_12 AC 17 ms
8,200 KB
testcase_13 AC 17 ms
8,152 KB
testcase_14 AC 17 ms
8,208 KB
testcase_15 AC 17 ms
8,224 KB
testcase_16 AC 17 ms
8,264 KB
testcase_17 AC 16 ms
8,264 KB
testcase_18 AC 17 ms
8,336 KB
testcase_19 AC 17 ms
8,220 KB
testcase_20 AC 16 ms
8,288 KB
testcase_21 AC 17 ms
8,244 KB
testcase_22 AC 17 ms
8,220 KB
testcase_23 AC 16 ms
8,316 KB
testcase_24 AC 17 ms
8,292 KB
testcase_25 AC 17 ms
8,196 KB
testcase_26 AC 17 ms
8,264 KB
testcase_27 AC 16 ms
8,192 KB
testcase_28 AC 17 ms
8,408 KB
testcase_29 AC 17 ms
8,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.110 しましまピラミッド
https://yukicoder.me/problems/no/110

"""
import sys
from sys import stdin
from bisect import bisect_left
input = stdin.readline


def solve(white_blocks, black_blocks):
    white_blocks.append(-1)
    white_blocks.sort()
    black_blocks.append(-1)
    black_blocks.sort()
    
    WHITE, BLACK = 0, 1
    blocks = [white_blocks, black_blocks]

    # 白いブロックを最初に使う場合
    ans_w = [white_blocks[-1]]
    next_block = BLACK
    while True:
        i = bisect_left(blocks[next_block], ans_w[-1])
        if blocks[next_block][i-1] == -1:
            break
        ans_w.append(blocks[next_block][i-1])
        next_block = BLACK if next_block == WHITE else WHITE

    # 黒いブロックを最初に使う場合
    ans_b = [black_blocks[-1]]
    next_block = WHITE
    while True:
        i = bisect_left(blocks[next_block], ans_b[-1])
        if blocks[next_block][i-1] == -1:
            break
        ans_b.append(blocks[next_block][i-1])
        next_block = BLACK if next_block == WHITE else WHITE

    return max(len(ans_w), len(ans_b))


def main(args):
    nw = int(input())
    white_blocks = [int(x) for x in input().split()]
    nb = int(input())
    black_blocks = [int(x) for x in input().split()]

    ans = solve(white_blocks, black_blocks)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0