結果

問題 No.274 The Wall
ユーザー kokoseikokosei
提出日時 2023-11-10 20:40:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 2,541 ms
コンパイル使用メモリ 215,748 KB
実行使用メモリ 11,512 KB
最終ジャッジ日時 2023-11-10 20:40:35
合計ジャッジ時間 3,833 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
8,312 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 5 ms
11,256 KB
testcase_12 AC 20 ms
11,512 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 8 ms
8,244 KB
testcase_15 AC 13 ms
10,400 KB
testcase_16 AC 4 ms
10,076 KB
testcase_17 AC 4 ms
10,076 KB
testcase_18 AC 4 ms
10,064 KB
testcase_19 AC 16 ms
10,524 KB
testcase_20 AC 18 ms
10,904 KB
testcase_21 AC 19 ms
11,152 KB
testcase_22 AC 5 ms
11,032 KB
testcase_23 AC 20 ms
11,168 KB
testcase_24 AC 20 ms
11,304 KB
testcase_25 AC 20 ms
11,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0