結果

問題 No.190 Dry Wet Moist
ユーザー kimiyukikimiyuki
提出日時 2016-11-01 17:46:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 89,044 KB
実行使用メモリ 13,012 KB
最終ジャッジ日時 2023-08-16 12:16:52
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 55 ms
7,340 KB
testcase_13 AC 69 ms
8,268 KB
testcase_14 AC 54 ms
7,252 KB
testcase_15 AC 75 ms
8,260 KB
testcase_16 AC 94 ms
9,428 KB
testcase_17 AC 13 ms
4,604 KB
testcase_18 AC 44 ms
6,848 KB
testcase_19 AC 92 ms
9,372 KB
testcase_20 AC 65 ms
7,684 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 128 ms
12,096 KB
testcase_23 AC 136 ms
13,012 KB
testcase_24 AC 109 ms
7,796 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 80 ms
9,112 KB
testcase_28 AC 37 ms
6,496 KB
testcase_29 AC 47 ms
7,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
template <typename T> T input(istream & in) { T a; in >> a; return a; }
int foo(vector<int> const & a) {
    int cnt = 0;
    for (int i = 0, j = a.size() - 1; i < j; ++ i, -- j) {
        while (i < j and a[i] + a[j] >= 0) -- j;
        if (i == j) break;
        ++ cnt;
    }
    return cnt;
}
int bar(vector<int> const & xs) {
    map<int,int> f, g;
    int zero = 0;
    for (int x : xs) {
        if (x > 0) {
            f[x] += 1;
        } else if (x < 0) {
            g[- x] += 1;
        } else {
            zero += 1;
        }
    }
    int cnt = 0;
    for (auto it : f) cnt += min(it.second, g[it.first]);
    cnt += zero/2;
    return cnt;
}
int main() {
    int n; cin >> n;
    vector<int> a(2*n); repeat (i,2*n) cin >> a[i];
    whole(sort, a);
    int dry   = foo(a);
    int moist = bar(a);
    repeat (i,2*n) a[i] *= -1; whole(reverse, a);
    int wet   = foo(a);
    cout << dry << ' ' << wet << ' ' << moist << endl;
    return 0;
}
0