結果
問題 |
No.274 The Wall
|
ユーザー |
![]() |
提出日時 | 2023-11-10 20:40:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,431 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 207,020 KB |
実行使用メモリ | 11,552 KB |
最終ジャッジ日時 | 2025-03-17 19:12:39 |
合計ジャッジ時間 | 2,956 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/scc> using namespace std; using ll = long long; const int mod = 998244353; int N, M; bool S[2010][4010]; int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for(int i = 0;i < N;i++){ int l, r; cin >> l >> r; for(int j = l;j <= r;j++){ S[i][j] = true; } } atcoder::scc_graph G(2 * N); for(int j = 0;j < (M + 1) / 2;j++){ int cnt = 0; vector<int> hit; for(int i = 0;i < N;i++){ cnt += S[i][j] + S[i][M - 1 - j]; if(S[i][j] || S[i][M - 1 - j]){ hit.push_back(i); } } if(cnt > 2){ cout << "NO" << endl; return 0; } if(cnt == 2 && hit.size() == 2){ if(S[hit[0]][j] ^ S[hit[1]][j]){ G.add_edge(hit[0], hit[1]); G.add_edge(hit[1], hit[0]); }else{ G.add_edge(hit[0], hit[1] + N); G.add_edge(hit[1], hit[0] + N); } } } vector<vector<int>> res = G.scc(); for(auto vec : res){ bool seen[2010] = {}; for(int v : vec){ if(v > N)v -= N; if(seen[v]){ cout << "NO" << endl; return 0; } seen[v] = true; } } cout << "YES" << endl; return 0; }