結果
問題 |
No.110 しましまピラミッド
|
ユーザー |
![]() |
提出日時 | 2020-11-21 19:33:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 5,000 ms |
コード長 | 1,287 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 201,996 KB |
最終ジャッジ日時 | 2025-01-16 04:09:21 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); } template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector<int> W(N); for (int i = 0; i < N; i++) cin >> W.at(i); int M; cin >> M; vector<int> B(M); for (int i = 0; i < M; i++) cin >> B.at(i); multiset<int> MS, MS2; for (auto a : W) MS.insert(a); for (auto a : B) MS2.insert(a); auto X = MS, Y = MS2; auto it = --X.end(); int now = *it; X.erase(it); int ans = 1; while (true) { it = Y.lower_bound(now); if (it == Y.begin()) break; it--; now = *it; Y.erase(it); ans++; it = X.lower_bound(now); if (it == X.begin()) break; it--; now = *it; X.erase(it); ans++; } X = MS2, Y = MS; it = --X.end(); now = *it; X.erase(it); int ans2 = 1; while (true) { it = Y.lower_bound(now); if (it == Y.begin()) break; it--; now = *it; Y.erase(it); ans2++; it = X.lower_bound(now); if (it == X.begin()) break; it--; now = *it; X.erase(it); ans2++; } cout << max(ans, ans2) << "\n"; }