結果

問題 No.274 The Wall
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-04-09 00:05:48
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,482 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 106,284 KB
実行使用メモリ 20,848 KB
最終ジャッジ日時 2023-09-04 00:30:38
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 19 ms
12,148 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 34 ms
20,848 KB
testcase_12 AC 44 ms
19,348 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 11 ms
5,972 KB
testcase_15 AC 27 ms
13,152 KB
testcase_16 AC 54 ms
18,748 KB
testcase_17 AC 51 ms
17,824 KB
testcase_18 AC 56 ms
18,088 KB
testcase_19 AC 48 ms
17,876 KB
testcase_20 AC 52 ms
18,588 KB
testcase_21 AC 54 ms
18,536 KB
testcase_22 AC 51 ms
19,856 KB
testcase_23 AC 50 ms
19,864 KB
testcase_24 AC 57 ms
19,336 KB
testcase_25 AC 59 ms
20,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
  }
}
0