結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 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 64 ms
8,696 KB
testcase_23 AC 78 ms
9,368 KB
testcase_24 AC 68 ms
8,692 KB
testcase_25 WA -
testcase_26 AC 1 ms
5,376 KB
testcase_27 WA -
testcase_28 AC 21 ms
5,632 KB
testcase_29 AC 24 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


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;
        };

        int z = 0;
        map<int, int> a;
        for(int i : p) a[i]++;
        for(int i : m) if(a[abs(i)] > 0) {
                z++;
                a[abs(i)]--;
            }
        
        cout << f(m, p, zero, -1) << " " << f(p, m, zero, 1) << " " << z << endl;;
        
        return 0;
    }
};

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