結果
問題 | No.274 The Wall |
ユーザー |
👑 |
提出日時 | 2019-04-09 00:05:48 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 2,482 bytes |
コンパイル時間 | 944 ms |
コンパイル使用メモリ | 118,824 KB |
実行使用メモリ | 20,456 KB |
最終ジャッジ日時 | 2024-06-13 05:00:05 |
合計ジャッジ時間 | 2,742 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
import std.conv, std.functional, std.stdio, std.string;import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;import core.bitop;class EOFException : Throwable { this() { super("EOF"); } }string[] tokens;string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }int readInt() { return readToken.to!int; }long readLong() { return readToken.to!long; }real readReal() { return readToken.to!real; }bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1;(unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }int N, M;int[] L, R;int[][] G;int[] colors;bool dfs(int u, int c) {colors[u] = c;foreach (v; 0 .. N) {if (G[u][v] != -1) {const cc = c ^ G[u][v];if (colors[v] == -1) {if (!dfs(v, cc)) {return false;}}if (colors[v] != cc) {return false;}}}return true;}void main() {try {for (; ; ) {N = readInt();M = readInt();L = new int[N];R = new int[N];foreach (u; 0 .. N) {L[u] = readInt();R[u] = readInt();}bool ans = true;G = new int[][](N, N);foreach (u; 0 .. N) {G[u][] = -1;}foreach (u; 0 .. N) {foreach (v; u + 1 .. N) {const f0 = (max(L[u], L[v]) <= min(R[u], R[v]));const f1 = (max(L[u], M - 1 - R[v]) <= min(R[u], M - 1 - L[v]));if (f0 && f1) {ans = false;} else if (f0) {G[u][v] = G[v][u] = 1;} else if (f1) {G[u][v] = G[v][u] = 1;}}}colors = new int[N];colors[] = -1;foreach (u; 0 .. N) {if (colors[u] == -1) {ans = ans && dfs(u, 0);}}writeln(ans ? "YES" : "NO");}} catch (EOFException e) {}}