結果
| 問題 |
No.190 Dry Wet Moist
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-04 16:26:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 294 ms / 2,000 ms |
| コード長 | 1,836 bytes |
| コンパイル時間 | 782 ms |
| コンパイル使用メモリ | 75,816 KB |
| 最終ジャッジ日時 | 2025-01-14 04:30:36 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
#include <iostream>
#include <set>
void solve() {
int n;
std::cin >> n;
n *= 2;
std::multiset<int> org;
while (n--) {
int x;
std::cin >> x;
org.insert(x);
}
// Dry
{
auto s = org;
int cnt = 0;
auto it = s.begin();
while (it != s.end()) {
auto x = *it;
it = s.erase(it);
// x + y < 0 <-> y < -x
auto nit = s.lower_bound(-x);
if (nit == s.begin()) continue;
++cnt;
--nit;
if (it == nit) {
it = s.erase(nit);
} else {
s.erase(nit);
}
}
std::cout << cnt << " ";
}
// Wet
{
auto s = org;
int cnt = 0;
auto it = s.begin();
while (it != s.end()) {
auto x = *it;
it = s.erase(it);
// x + y > 0 <-> y > -x
auto nit = s.upper_bound(-x);
if (nit == s.end()) continue;
++cnt;
if (it == nit) {
it = s.erase(nit);
} else {
s.erase(nit);
}
}
std::cout << cnt << " ";
}
// Moist
{
auto s = org;
int cnt = 0;
auto it = s.begin();
while (it != s.end()) {
auto x = *it;
it = s.erase(it);
// x + y = 0 <-> y = -x
auto nit = s.find(-x);
if (nit == s.end()) continue;
++cnt;
if (it == nit) {
it = s.erase(nit);
} else {
s.erase(nit);
}
}
std::cout << cnt << "\n";
}
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}