結果

問題 No.190 Dry Wet Moist
ユーザー imulanimulan
提出日時 2016-12-09 18:18:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,575 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 171,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 05:48:03
合計ジャッジ時間 4,501 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 21 ms
4,380 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 36 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 36 ms
4,376 KB
testcase_20 AC 25 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 47 ms
4,380 KB
testcase_23 AC 46 ms
4,376 KB
testcase_24 AC 48 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 30 ms
4,376 KB
testcase_28 AC 14 ms
4,376 KB
testcase_29 AC 18 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

vi p,m;
int P,M;
int z=0;

int Dry()
{
    sort(all(m),greater<int>());
    sort(all(p),greater<int>());

    int ret=0;
    int z_rem=z;

    int p_idx=0;
    rep(m_idx,M)
    {
        while(p_idx<P && m[m_idx]<=p[p_idx]) ++p_idx;

        if(p_idx==P && z_rem==0)
        {
            ret+=(M-m_idx)/2;
            break;
        }

        if(p_idx==P)
        {
            --z_rem;
            ++ret;
        }
        else
        {
            ++ret;
            ++p_idx;
        }
    }

    return ret;
}

int Wet()
{
    swap(p,m);
    swap(P,M);

    int ret = Dry();

    swap(p,m);
    swap(P,M);

    return ret;
}

int Moist()
{
    sort(all(m));
    sort(all(p));

    int ret=z/2;

    int p_idx=0,m_idx=0;
    while(p_idx<P && m_idx<M)
    {
        if(p[p_idx] < m[m_idx]) ++p_idx;
        else if(p[p_idx] > m[m_idx]) ++m_idx;
        else
        {
            ++p_idx;
            ++m_idx;
            ++ret;
        }
    }

    return ret;
}

int main()
{
    int n;
    scanf(" %d", &n);

    rep(i,2*n)
    {
        int a;
        scanf(" %d", &a);
        if(a>0) p.pb(a);
        else if(a<0) m.pb(-a);
        else ++z;
    }

    P=p.size();
    M=m.size();
    printf("%d %d %d\n", Dry(), Wet(), Moist());
    return 0;
}
0