結果

問題 No.190 Dry Wet Moist
ユーザー cormorancormoran
提出日時 2016-11-01 17:24:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,633 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 166,268 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 20:41:09
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 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 34 ms
5,376 KB
testcase_23 AC 38 ms
5,376 KB
testcase_24 AC 35 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()

template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(2 * N); cin >> A;
        vector<int> p, m;
        int zero = 0;
        for(int a : A) {
            zero += a == 0;
            if(a > 0) p.push_back(a);
            if(a < 0) m.push_back(a);
        }
        sort(all(p), greater<int>());        
        sort(all(m));

        auto f = [](const vector<int> &p, const vector<int> &m, int zero, int sign) {            
            int ret = 0;
            if(p.size() > 0) {
                int pi = 0;
                for(int mv : m) {
                    if((sign == 0 and mv + p[pi] == 0) or
                       (mv + p[pi]) * sign > 0) {
                        ret++;
                        pi++;
                    }
                    if(pi >= p.size()) break;
                }
                if(sign != 0) {
                    int a = min<int>(p.size() - pi, zero);
                    ret += a;
                    pi += a;
                    ret += (p.size() - pi) / 2;
                }
            }
            if(sign == 0) ret += zero / 2;
            return ret;
        };
        
        cout << f(m, p, zero, -1) << " " << f(p, m, zero, 1) << " " << f(p, m, zero, 0) << endl;;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0