結果

問題 No.1244 Black Segment
コンテスト
ユーザー 👑 tttmmmyyyy
提出日時 2026-11-04 22:40:07
言語 Fix
(1.6.0 + cp-library + minilib)
コンパイル:
fix_c _filename_
実行:
./a.out
結果
AC  
実行時間 22 ms / 2,000 ms
+ 178µs
コード長 1,449 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,333 ms
コンパイル使用メモリ 668,812 KB
実行使用メモリ 11,128 KB
最終ジャッジ日時 2026-11-04 22:40:45
合計ジャッジ時間 16,454 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます
コンパイルメッセージ
make: 'lib.o' は更新済みです.

ソースコード

diff #
raw source code

module Main;

// import BinaryHeap;
// import BoolArray;
// import CPLib.Arithmetic;
// import CPLib.Bipartite;
// import CPLib.Bits;
// import CPLib.Convolution;
// import CPLib.DSegtree;
import CPLib.Graph;
import CPLib.IO;
// import CPLib.LDSegtree;
// import CPLib.LSegtree;
// import CPLib.MaxFlow;
// import CPLib.Memoize;
// import CPLib.MinCostFlow;
// import CPLib.Misc;
// import CPLib.Monoid;
// import CPLib.Segtree;
// import CPLib.String;
import CPLib.Trait;
// import CPLib.TwoSat;
// import CPLib.UnionFind;
// import CPLib.ZP;
// import HashMap;
// import HashSet;

main : IO () = (
    let iN = *read_i;
    let iM = *read_i;
    let iA = *read_i - 1;
    let iB = *read_i;
    let graph = GraphBuilder::create(iN + 3);
    let start = iN + 1;
    let end = iN + 2;
    let graph = *range(0, iM).fold_m(graph, |m, graph|
        let iL = *read_i - 1;
        let iR = *read_i;
        let graph = graph.add_edge(iL, iR, 1).add_edge(iR, iL, 1);
        let graph = if iL <= iA { graph.add_edge(start, iL, 0) } else { graph };
        let graph = if iR <= iA { graph.add_edge(start, iR, 0) } else { graph };
        let graph = if iB <= iR { graph.add_edge(iR, end, 0) } else { graph };
        let graph = if iB <= iL { graph.add_edge(iL, end, 0) } else { graph };
        graph.pure
    );
    let ans = graph.build.dijkstra(start).@(end);
    let ans = if ans == inf { -1 } else { ans };
    ans.to_string.println;;
    pure()
);
0