結果

問題 No.110 しましまピラミッド
コンテスト
ユーザー d_razerart
提出日時 2026-02-04 22:39:14
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 1,187 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,938 ms
コンパイル使用メモリ 217,488 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-04 22:39:20
合計ジャッジ時間 4,766 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int first_smaller(const vector<int>& arr, int x) {
    int l = 0, r = arr.size() - 1;
    int ans = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (arr[mid] < x) {
            ans = arr[mid];
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    return ans;
}

int main() {
    int nw, nb;
    cin >> nw;
    vector<int> w(nw);
    for (int i = 0; i < nw; i++) cin >> w[i];

    cin >> nb;
    vector<int> b(nb);
    for (int i = 0; i < nb; i++) cin >> b[i];

    sort(w.begin(), w.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());

    int curr;
    bool fromW;

    if (w[0] > b[0]) {
        curr = w[0];
        fromW = true;
    } else {
        curr = b[0];
        fromW = false;
    }

    int count = 1;

    while (true) {
        int next;
        if (fromW) {
            next = first_smaller(b, curr);
            if (next == -1) break;
        } else {
            next = first_smaller(w, curr);
            if (next == -1) break;
        }
        curr = next;
        fromW = !fromW;
        count++;
    }

    cout << count << endl;
    return 0;
}
0