結果

問題 No.190 Dry Wet Moist
ユーザー kimiyuki
提出日時 2016-11-01 17:46:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 88,588 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-11-25 00:58:11
合計ジャッジ時間 3,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
template <typename T> T input(istream & in) { T a; in >> a; return a; }
int foo(vector<int> const & a) {
int cnt = 0;
for (int i = 0, j = a.size() - 1; i < j; ++ i, -- j) {
while (i < j and a[i] + a[j] >= 0) -- j;
if (i == j) break;
++ cnt;
}
return cnt;
}
int bar(vector<int> const & xs) {
map<int,int> f, g;
int zero = 0;
for (int x : xs) {
if (x > 0) {
f[x] += 1;
} else if (x < 0) {
g[- x] += 1;
} else {
zero += 1;
}
}
int cnt = 0;
for (auto it : f) cnt += min(it.second, g[it.first]);
cnt += zero/2;
return cnt;
}
int main() {
int n; cin >> n;
vector<int> a(2*n); repeat (i,2*n) cin >> a[i];
whole(sort, a);
int dry = foo(a);
int moist = bar(a);
repeat (i,2*n) a[i] *= -1; whole(reverse, a);
int wet = foo(a);
cout << dry << ' ' << wet << ' ' << moist << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0