結果
問題 | No.274 The Wall |
ユーザー |
|
提出日時 | 2015-08-05 21:21:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 842 bytes |
コンパイル時間 | 914 ms |
コンパイル使用メモリ | 72,376 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-17 18:46:10 |
合計ジャッジ時間 | 2,308 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; bool solve(){ int N, M; cin >> N >> M; vector<pair<int,int>> intervals; for(int i=0;i<N;i++){ int L, R; cin >> L >> R; if(L < M - R - 1){ intervals.emplace_back(L, R); } else { intervals.emplace_back(M - R - 1, M - L - 1); } } sort(intervals.begin(), intervals.end()); int L = 0, R = M - 1; for(auto ps : intervals){ bool right = false; if(L <= ps.first){ // 左におくべき if(R < ps.second){ return false; } L = ps.second + 1; } else if(M - ps.first - 1 <= R){ // 右におくべき if(M - ps.second - 1 < L){ return false; } R = M - ps.second - 1 - 1; } else { // ダメポ return false; } } return true; } int main(){ cout << (solve() ? "YES" : "NO") << endl; return 0; }