結果

問題 No.190 Dry Wet Moist
ユーザー rpy3cpprpy3cpp
提出日時 2015-04-22 10:37:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,762 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 32,744 KB
最終ジャッジ日時 2023-09-18 08:07:03
合計ジャッジ時間 5,214 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,776 KB
testcase_01 AC 17 ms
7,888 KB
testcase_02 AC 17 ms
7,788 KB
testcase_03 AC 17 ms
7,852 KB
testcase_04 AC 17 ms
7,860 KB
testcase_05 AC 16 ms
7,828 KB
testcase_06 AC 16 ms
7,788 KB
testcase_07 WA -
testcase_08 AC 18 ms
8,216 KB
testcase_09 AC 17 ms
8,252 KB
testcase_10 WA -
testcase_11 AC 18 ms
8,344 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 285 ms
32,696 KB
testcase_23 AC 424 ms
32,744 KB
testcase_24 AC 298 ms
29,996 KB
testcase_25 WA -
testcase_26 AC 16 ms
8,296 KB
testcase_27 WA -
testcase_28 AC 125 ms
14,792 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def find_max_moist(As):
    '''2N個の整数のリスト As をN個のペアにしたとき、ペアの和が 0 となる個数の最大値を求める。
    '''
    Aplus = [a for a in As if a > 0]
    Aminus = [-a for a in As if a < 0]
    Aplus.sort()
    Aminus.sort()
    A0 = [a for a in As if a == 0]
    count = len(A0)
    p = m = 0
    while p < len(Aplus) and m < len(Aminus):
        if Aplus[p] == Aminus[m]:
            count += 1
            p += 1
            m += 1
        elif Aplus[p] > Aminus[m]:
            m += 1
        else:
            p += 1
    return count


def find_max_wet(As):
    '''2N個の整数のリストAsをN個のペアにしたとき、ペアの和が正となる個数の最大値を求める。
    正のリストと、その他のリストとに分け、絶対値の降順に並べ換えて、貪欲法でペアを作っていく。
    それぞれのリストにカーソルをおき、マージソートのようにカーソルを移動させていく。
    '''
    Aplus = [a for a in As if a > 0]
    Arest = [-a for a in As if a <= 0]
    Aplus.sort(reverse=True)
    Arest.sort(reverse=True)
    lenAplus = len(Aplus)
    lenArest = len(Arest)
    count = 0
    p = r = 0
    while p < lenAplus and r < lenArest:
        if Aplus[p] > Arest[r]:
            count += 1
            p += 1
            r += 1
        else:
            r += 1
    if p < lenAplus:
        count += (lenAplus - p) // 2
    return count


def find_max_dry(As):
    minusAs = [-a for a in As]
    return find_max_wet(minusAs)


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split()))
    dry = find_max_dry(As)
    wet = find_max_wet(As)
    moist = find_max_moist(As)
    print(dry, wet, moist)
0