結果

問題 No.200 カードファイト!
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-20 01:30:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,768 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 8,252 KB
最終ジャッジ日時 2023-09-22 19:36:27
合計ジャッジ時間 2,022 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 17 ms
8,100 KB
testcase_03 AC 17 ms
8,156 KB
testcase_04 AC 16 ms
8,224 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 17 ms
8,040 KB
testcase_14 AC 16 ms
8,160 KB
testcase_15 AC 16 ms
8,156 KB
testcase_16 AC 16 ms
8,032 KB
testcase_17 AC 16 ms
8,024 KB
testcase_18 AC 17 ms
8,156 KB
testcase_19 AC 16 ms
8,104 KB
testcase_20 WA -
testcase_21 AC 17 ms
8,024 KB
testcase_22 AC 17 ms
8,108 KB
testcase_23 AC 16 ms
8,044 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
8,152 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N = int(input())
    A = int(input())
    Bs = list(map(int, input().split()))
    C = int(input())
    Ds = list(map(int, input().split()))
    return N, A, Bs, C, Ds

def solve(N, A, Bs, C, Ds):
    Bs.sort()
    Ds.sort()
    minA = min(Bs)
    maxA = max(Bs)
    minC = min(Ds)
    maxC = max(Ds)
    if minA > maxC:
        return N
    if maxA < minC:
        return 0
    if C >= A:
        return solve_C_is_longer(N, A, Bs, C, Ds)
    else:
        return solve_A_is_longer(N, A, Bs, C, Ds)
    
def solve_C_is_longer(N, A, Bs, C, Ds):
    repeat, residue = divmod(N, C)
    Cs = Ds * repeat + Ds[:residue]
    repeat, residue = divmod(N, A)
    n_win = 0
    for r in range(repeat):
        subCs = Cs[r*A:(r+1)*A]
        n_win += count_wins(Bs, subCs)
    if residue:
        subCs = Cs[-residue:]
        subAs = Bs[-residue:]
        n_win += count_wins(subAs, subCs)
    return n_win

def solve_A_is_longer(N, A, Bs, C, Ds):
    Bs.sort(reverse=True)
    repeat, residue = divmod(N, A)
    As = Bs * repeat + Bs[:residue]
    repeat, residue = divmod(N, C)
    n_win = 0
    for r in range(repeat):
        subAs = As[r*C:(r+1)*C]
        n_win += count_wins(subAs, Ds)
    if residue:
        subAs = As[-residue:]
        subCs = Ds[:residue]
        n_win += count_wins(subAs, subCs)
    return n_win

def count_wins(As, Cs):
    N = len(As)
    Acopy = As[:]
    Ccopy = Cs[:]
    Acopy.sort()
    Ccopy.sort()
    idxA = 0
    n_win = 0
    for c in Ccopy:
        while Acopy[idxA] <= c:
            idxA += 1
            if idxA == N:
                return n_win
        n_win += 1
        idxA += 1
        if idxA == N:
            return n_win
    return n_win

N, A, Bs, C, Ds = read_data()
print(solve(N, A, Bs, C, Ds))
0