結果

問題 No.110 しましまピラミッド
ユーザー ama_nukoama_nuko
提出日時 2018-06-11 17:44:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,420 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 99,248 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 04:04:09
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int nw;
    cin >> nw;
    vector<int> w(nw);
    rep(i, nw) cin >> w[i];
    int nb;
    cin >> nb;
    vector<int> b(nb);
    rep(i, nb) cin >> b[i];
    sort(w.begin(), w.end());
    sort(b.begin(), b.end());

    vector<vector<int>> dp(2, vector<int>(21));
    int wi = 0;
    int bi = 0;
    if(w[wi] < b[bi]){
        dp[0][w[wi++]] = 1;
    }else if(w[wi] > b[bi]){
        dp[1][b[bi++]] = 1;
    }else{
        dp[0][w[wi++]] = 1;
        dp[1][b[bi++]] = 1;
    }
    while(wi < nw || bi < nb){
        if((wi < nw && bi < nb && w[wi] < b[bi]) || bi >= nb){
            for(int i = 0; b[i] < w[wi]; i++){
                dp[0][w[wi]] = max(dp[0][w[wi]], dp[1][b[i]] + 1);
            }
            wi++;
            continue;
        }

        for(int i = 0; w[i] < b[bi]; i++){
            dp[1][b[bi]] = max(dp[1][b[bi]], dp[0][w[i]] + 1);
        }
        bi++;
    }

    int ans = 0;
    rep(i, 2){
        rep(j, 21){
            if(dp[i][j] > ans){
                ans = dp[i][j];
            }
        }
    }
    cout<< ans << endl;
    return 0;
}
0