結果

問題 No.190 Dry Wet Moist
コンテスト
ユーザー mamekin
提出日時 2015-05-24 14:55:03
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,197 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 729 ms
コンパイル使用メモリ 118,848 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-27 17:59:03
合計ジャッジ時間 3,035 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

template<class T>
int solve(const vector<int>& a, T comp)
{
    int n = a.size();
    int i = 0;
    int j = n - 1;

    int ans = 0;
    while(i < j){
        int x = comp(a[i], a[j]);
        if(x == 0){
            ++ ans;
            ++ i;
            -- j;
        }
        else if(x < 0){
            ++ i;
        }
        else{
            -- j;
        }
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(2*n);
    for(int i=0; i<2*n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());

    int dry   = solve(a, [](int x, int y){ return max(0, y + x + 1); });
    int wet   = solve(a, [](int x, int y){ return min(0, y + x - 1); });
    int moist = solve(a, [](int x, int y){ return y + x; });
    cout << dry << ' ' << wet << ' ' << moist << endl;

    return 0;
}
0