結果

問題 No.110 しましまピラミッド
ユーザー satanicsatanic
提出日時 2016-04-23 16:03:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,528 bytes
コンパイル時間 727 ms
コンパイル使用メモリ 78,000 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 03:53:30
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 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,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:49:49: 警告: ‘readLen’ may be used uninitialized [-Wmaybe-uninitialized]
   49 |             if(len_black[i].second==colorBlackF && len_black[i].first<readLen){
main.cpp:37:13: 備考: ‘readLen’ はここで定義されています
   37 |         int readLen;
      |             ^~~~~~~
main.cpp:48:20: 警告: ‘readPos’ may be used uninitialized [-Wmaybe-uninitialized]
   48 |         for(size_t i=readPos; i<len_black.size(); ++i){
      |                    ^
main.cpp:36:13: 備考: ‘readPos’ はここで定義されています
   36 |         int readPos;
      |             ^~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    //input
    std::vector<std::pair<int, bool>> len_black;
    int nw;
    std::cin >> nw;
    for(int i=0; i<nw; ++i){
        int w;
        std::cin >> w;
        len_black.push_back(std::make_pair(w, false));
    }
    int nb;
    std::cin >> nb;
    for(int i=0; i<nb; ++i){
        int b;
        std::cin >> b;
        len_black.push_back(std::make_pair(b, true));
    }
    
    //sort
    std::sort(len_black.begin(), len_black.end(), [](const auto& l, const auto& r){
        return l.first>r.first;
    });
    
    //solve
    int ans = -1;
    for(int color=0; color<2; ++color){
        int tmpAns = 0;
        int readPos;
        int readLen;
        bool colorBlackF = (color==0) ? false : true;
        //search first block
        for(size_t i=0; i<len_black.size(); ++i){
            if(len_black[i].second==colorBlackF){
                readPos=i;
                readLen=len_black[i].first+1;
                break;
            }
        }
        //count putable block
        for(size_t i=readPos; i<len_black.size(); ++i){
            if(len_black[i].second==colorBlackF && len_black[i].first<readLen){
                ++tmpAns;
                colorBlackF=!colorBlackF;
                readLen=len_black[i].first;
            }
        }
        ans = std::max(ans, tmpAns);
    }
    
    //output
    std::cout << ans << "\n";

    return 0;
}
0