結果

問題 No.190 Dry Wet Moist
ユーザー y_mazuny_mazun
提出日時 2015-04-24 00:00:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 73,628 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2023-09-18 08:47:27
合計ジャッジ時間 2,763 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 33 ms
5,556 KB
testcase_13 AC 42 ms
5,972 KB
testcase_14 AC 31 ms
5,424 KB
testcase_15 AC 46 ms
6,324 KB
testcase_16 AC 57 ms
6,744 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 27 ms
5,312 KB
testcase_19 AC 56 ms
6,704 KB
testcase_20 AC 39 ms
5,900 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 75 ms
7,344 KB
testcase_23 AC 89 ms
8,144 KB
testcase_24 AC 76 ms
7,284 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 51 ms
6,444 KB
testcase_28 AC 23 ms
5,276 KB
testcase_29 AC 29 ms
5,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int solvePlus(vector<int> &p, vector<int> &m, vector<int> &z){
  int cnt = 0;

  int pp = 0;
  int mp = 0;

  while(pp < (int)p.size() && mp < (int)m.size()){
    while(pp < (int)p.size() && p[pp] <= m[mp]) pp++;
    if(pp != (int)p.size()) cnt++;
    mp++; pp++;
  }

  int rest = p.size() - cnt;
  int zc = min(rest, (int)z.size());
  rest -= zc;

  return cnt + zc + rest / 2;
}

int solveMinus(vector<int> &p, vector<int> &m, vector<int> &z){
  return solvePlus(m, p, z);
}

int solveZero(vector<int> &p, vector<int> &m, vector<int> &z){
  map<int, int> mc;
  REP(i,m.size()) mc[m[i]]++;

  int ret = z.size() / 2;
  REP(i,p.size()){
    if(mc[p[i]] > 0){
      ret++;
      mc[p[i]]--;
    }
  }

  return ret;
}

int main(){
  const int n = getInt();
  vector<int> p;
  vector<int> m;
  vector<int> z;

  REP(i,2*n){
    const int a = getInt();
    if(a == 0) z.push_back(a);
    else if(a > 0) p.push_back(a);
    else m.push_back(-a);
  }

  sort(p.begin(), p.end());
  sort(m.begin(), m.end());

  const int dry = solveMinus(p, m, z);
  const int wet = solvePlus(p, m, z);
  const int moist = solveZero(p, m, z);

  printf("%d %d %d\n", dry, wet, moist);

  return 0;
}
0