結果

問題 No.110 しましまピラミッド
ユーザー kpinkcatkpinkcat
提出日時 2023-10-23 10:03:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,827 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 206,860 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 10:03:24
合計ジャッジ時間 4,203 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int main(){
    int nw, nb, pw = 0, pb = 0, answ = 0, ansb = 0;
    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());
    sort(b.begin(), b.end(), greater());
    
    // black first -> white を探索
    if (nb) ansb++;
    bool found = false;
    for (int i = pw; i < nw; i++){
        if (w[i] < b[pb]){
            ansb++;
            pw = i+1;
            pb++;
            found = true;
            if (pb == nb) break;
        }
        if (found){
            for (int j = pb; j < nb; j ++){
                if (w[i] > b[j]){
                    ansb++;
                    pb = j;
                    found = false;
                    break;
                }
            }
            if (pb == nb) break;
        }
        if (pb == nb) break;
        if (found) break;
    }
    pb = 0;
    pw = 0;
    if (nw) answ++;
    found = false;
    for (int i = pb; i < nb; i++){
        if (b[i] < w[pw]){
            answ++;
            pb = i+1;
            pw++;
            found = true;
            if (pw == nw) break;
        }
        if (found){
            for (int j = pw; j < nw; j ++){
                if (b[i] > w[j]){
                    answ++;
                    pw = j;
                    found = false;
                    break;
                }
            }
            if (pw == nw) break;
        }
        if (pw == nw) break;
        if (found) break;
    }
    cout << max(answ, ansb) << endl;
}
0