結果
問題 |
No.110 しましまピラミッド
|
ユーザー |
![]() |
提出日時 | 2019-03-28 08:47:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,808 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 112,168 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-31 11:51:17 |
合計ジャッジ時間 | 2,645 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <list> #include <set> #include <map> #include <numeric> #include <regex> #include <tuple> using namespace std; typedef long long ll; typedef pair<int, int> P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 int main() { cin.tie(0); ios::sync_with_stdio(false); int N1; cin >> N1; priority_queue<int> W; for (int i = 0; i < N1; i++) { int tmp; cin >> tmp; W.push(tmp); } int N2; cin >> N2; priority_queue<int> B; for (int i = 0; i < N2; i++) { int tmp; cin >> tmp; B.push(tmp); } int fw = 0; bool color = 1; // 1 : 次に乗せる色は白 int under = INF; bool flag = true; priority_queue<int> tmpW = W; priority_queue<int> tmpB = B; while (flag) { flag = false; if (color) { while (!tmpW.empty() && tmpW.top() >= under) tmpW.pop(); if (!tmpW.empty()) { under = tmpW.top(); tmpW.pop(); fw++; color = false; flag = true; } } else { while (!tmpB.empty() && tmpB.top() >= under) tmpB.pop(); if (!tmpB.empty()) { under = tmpB.top(); tmpB.pop(); fw++; color = true; flag = true; } } } int fb = 0; color = 0; // 1 : 次に乗せる色は白 under = INF; flag = true; tmpW = W; tmpB = B; while (flag) { flag = false; if (color) { while (!tmpW.empty() && tmpW.top() >= under) tmpW.pop(); if (!tmpW.empty()) { under = tmpW.top(); tmpW.pop(); fb++; color = false; flag = true; } } else { while (!tmpB.empty() && tmpB.top() >= under) tmpB.pop(); if (!tmpB.empty()) { under = tmpB.top(); tmpB.pop(); fb++; color = true; flag = true; } } } cout << max(fw, fb) << endl; return 0; }