結果

問題 No.190 Dry Wet Moist
ユーザー nebukuro09nebukuro09
提出日時 2016-09-29 11:57:13
言語 Python2
(2.7.18)
結果
AC  
実行時間 533 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 34,196 KB
最終ジャッジ日時 2024-05-01 07:41:02
合計ジャッジ時間 5,217 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,912 KB
testcase_01 AC 14 ms
6,784 KB
testcase_02 AC 14 ms
6,912 KB
testcase_03 AC 13 ms
6,912 KB
testcase_04 AC 13 ms
6,912 KB
testcase_05 AC 13 ms
6,656 KB
testcase_06 AC 14 ms
6,784 KB
testcase_07 AC 16 ms
7,168 KB
testcase_08 AC 15 ms
6,940 KB
testcase_09 AC 14 ms
6,784 KB
testcase_10 AC 14 ms
6,784 KB
testcase_11 AC 14 ms
6,912 KB
testcase_12 AC 213 ms
18,556 KB
testcase_13 AC 272 ms
19,740 KB
testcase_14 AC 207 ms
18,448 KB
testcase_15 AC 291 ms
20,204 KB
testcase_16 AC 374 ms
22,088 KB
testcase_17 AC 54 ms
9,728 KB
testcase_18 AC 173 ms
17,908 KB
testcase_19 AC 368 ms
21,788 KB
testcase_20 AC 252 ms
19,416 KB
testcase_21 AC 39 ms
8,056 KB
testcase_22 AC 249 ms
24,164 KB
testcase_23 AC 533 ms
34,196 KB
testcase_24 AC 243 ms
24,180 KB
testcase_25 AC 13 ms
6,784 KB
testcase_26 AC 13 ms
6,912 KB
testcase_27 AC 323 ms
20,912 KB
testcase_28 AC 143 ms
17,264 KB
testcase_29 AC 184 ms
18,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

N = input()
A = sorted(map(int, raw_input().split()))
nega = []
zero = []
posi = []
for a in A:
    if a < 0:
        nega.append(a)
    elif a == 0:
        zero.append(a)
    else:
        posi.append(a)

if len(nega) == 0:
    print 0, min(len(posi),len(zero))+max(0, len(posi)-len(zero))/2, len(zero)/2
    exit()
if len(posi) == 0:
    print min(len(nega),len(zero))+max(0, len(nega)-len(zero))/2, 0, len(zero)/2
    exit()

nega_n = 0
p1 = 0
p2 = len(posi)-1
while p1 < len(nega) and p2 >= 0:
    if nega[p1]+posi[p2] < 0:
        p1 += 1
        p2 -= 1
        nega_n += 1
    else:
        p2 -= 1
nega_n += min(len(zero), len(nega)-nega_n) + max(0,(len(nega)-nega_n-len(zero))/2)

posi_n = 0
p1 = 0
p2 = len(posi)-1
while p1 < len(nega) and p2 >= 0:
    if nega[p1]+posi[p2] > 0:
        p1 += 1
        p2 -= 1
        posi_n += 1
    else:
        p1 += 1
posi_n += min(len(zero), len(posi)-posi_n) + max(0,(len(posi)-posi_n-len(zero))/2)

nega = map(abs, nega)
c1 = Counter(nega)
c2 = Counter(posi)
moist = len(zero)/2
for k in c1:
    moist += min(c1[k], c2[k])

print nega_n, posi_n, moist
0