結果

問題 No.274 The Wall
ユーザー tatanaideyotatanaideyo
提出日時 2018-11-18 11:10:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,759 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 80,856 KB
実行使用メモリ 132,148 KB
最終ジャッジ日時 2023-08-26 01:53:36
合計ジャッジ時間 3,554 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 134 ms
68,852 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 375 ms
132,148 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 111 ms
39,172 KB
testcase_17 AC 108 ms
38,640 KB
testcase_18 AC 120 ms
41,748 KB
testcase_19 AC 21 ms
4,376 KB
testcase_20 AC 25 ms
4,376 KB
testcase_21 AC 25 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 27 ms
4,376 KB
testcase_24 AC 26 ms
4,380 KB
testcase_25 AC 27 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:13:29: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   13 |     void Dfs(const int cur, auto &ord) {
      |                             ^~~~
main.cpp:63:22: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   63 | inline bool Is(const auto &s1, const auto &s2) {
      |                      ^~~~
main.cpp:63:38: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   63 | inline bool Is(const auto &s1, const auto &s2) {
      |                                      ^~~~

ソースコード

diff #

#include <iostream>
#include <vector>

struct Graph {
    const int n;
    std::vector<std::vector<int>> adj, radj;
    std::vector<int> scc;

    Graph(int _n) : n(_n), adj(n), radj(n), scc(n, false) {}

    void add_edge(int src, int dst) { adj[src].push_back(dst); radj[dst].push_back(src); }

    void Dfs(const int cur, auto &ord) {
        scc[cur] = true;
        for (auto dst : adj[cur])
            if (!scc[dst]) Dfs(dst, ord);
        ord.push_back(cur);
    }
    void RevDfs(const int id, const int cur) {
        scc[cur] = id;
        for (auto dst : radj[cur])
            if (scc[dst] == -1) RevDfs(id, dst);
    }

    void StronglyConnectedComponents() {
        std::vector<int> ord;
        for (int v = 0; v < n; ++v)
            if (!scc[v]) Dfs(v, ord);

        std::fill(scc.begin(), scc.end(), -1);
        for (int i = n - 1, no = 0; 0 <= i; --i)
            if (scc[ord[i]] == -1) RevDfs(no++, ord[i]);
    }
};

// -------------8<------- start of library -------8<------------------------
struct TwoSat {
    const int n;
    bool is_sat;
    std::vector<bool> sol;
    Graph g;

    TwoSat(int _n) : n(_n), is_sat(true), sol(n, true), g(2 * n) {}

    void add_closure(int x1, bool lt1, int x2, bool lt2) {
        g.add_edge((x1 + n * !lt1 + n) % (2 * n), x2 + n * !lt2);
        g.add_edge((x2 + n * !lt2 + n) % (2 * n), x1 + n * !lt1);
    }

    bool Check() const { return is_sat; }
    bool Solve() {
        g.StronglyConnectedComponents();

        for (int x = 0; x < n; ++x) {
            if (g.scc[x] == g.scc[x + n]) is_sat = false;
            else if (g.scc[x] < g.scc[x + n]) sol[x] = false;
        }
        return is_sat;
    }
};
// -------------8<------- end of library ---------8-------------------------

inline bool Is(const auto &s1, const auto &s2) {
    return (s1.first <= s2.first && s2.first <= s1.second)
        || (s1.first <= s2.second && s2.second <= s1.second);
}

int main() {
    std::cin.tie(0); std::ios::sync_with_stdio(false);

    int n, m;
    std::cin >> n >> m;

    std::vector<std::pair<int, int>> seg(n), rseg(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> seg[i].first >> seg[i].second;
        rseg[i] = std::make_pair(m - 1 - seg[i].second, m - 1 - seg[i].first);
    }

    TwoSat sat(n);
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (Is(seg[i], seg[j])) sat.add_closure(i, false, j, false);
            if (Is(seg[i], rseg[j])) sat.add_closure(i, false, j, true);
            if (Is(rseg[i], seg[j])) sat.add_closure(i, true, j, false);
            if (Is(rseg[i], rseg[j])) sat.add_closure(i, true, j, true);
        }
    }

    if (sat.Solve()) std::cout << "YES\n";
    else std::cout << "NO\n";

    return 0;
}
0