結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 16 ms
8,120 KB
testcase_03 AC 16 ms
8,128 KB
testcase_04 AC 16 ms
7,992 KB
testcase_05 AC 16 ms
8,000 KB
testcase_06 WA -
testcase_07 AC 16 ms
8,104 KB
testcase_08 AC 16 ms
8,176 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 16 ms
8,132 KB
testcase_14 AC 16 ms
8,028 KB
testcase_15 AC 16 ms
8,076 KB
testcase_16 AC 16 ms
8,020 KB
testcase_17 AC 16 ms
8,132 KB
testcase_18 AC 16 ms
7,996 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 17 ms
8,024 KB
testcase_22 AC 16 ms
8,028 KB
testcase_23 AC 17 ms
8,096 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
8,176 KB
testcase_27 AC 16 ms
8,068 KB
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
    return n_win

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