結果
問題 | No.110 しましまピラミッド |
ユーザー |
|
提出日時 | 2016-04-23 16:03:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,528 bytes |
コンパイル時間 | 962 ms |
コンパイル使用メモリ | 76,500 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-31 11:18:38 |
合計ジャッジ時間 | 1,704 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:49:49: warning: 'readLen' may be used uninitialized [-Wmaybe-uninitialized] 49 | if(len_black[i].second==colorBlackF && len_black[i].first<readLen){ main.cpp:37:13: note: 'readLen' was declared here 37 | int readLen; | ^~~~~~~ main.cpp:48:20: warning: 'readPos' may be used uninitialized [-Wmaybe-uninitialized] 48 | for(size_t i=readPos; i<len_black.size(); ++i){ | ^ main.cpp:36:13: note: 'readPos' was declared here 36 | int readPos; | ^~~~~~~
ソースコード
#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; }