結果

問題 No.274 The Wall
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-12-02 17:32:52
言語 D
(dmd 2.107.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,744 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 146,980 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 23:14:34
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 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,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 38 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 22 ms
4,376 KB
testcase_21 AC 21 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 23 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int N, M; readf("%s %s\n", &N, &M);
    auto L = new int[N],
         R = new int[N];
    foreach (i; 0 .. N) {
        readf("%s %s\n", &L[i], &R[i]);
    }
    alias P = Tuple!(int, int);
    void rot(ref int l, ref int r) {
        int nl = M - 1 - r;
        int nr = M - 1 - l;
        l = nl; r = nr;
    }
    bool solve() {
        auto used = new bool[M];
        auto set = new bool[N];
        bool flag = true;
        while (flag) {
            flag = false;
            foreach (i; 0 .. N) {
                if (set[i]) continue;
                int l0 = L[i], r0 = R[i],
                l1 = L[i], r1 = R[i];
                rot(l1, r1);
                if (used[l0 .. r0 + 1].any) {
                    if (used[l1 .. r1 + 1].any) return false;
                    used[l1 .. r1 + 1] = true;
                    set[i] = true;
                    flag = true;
                } else {
                    if (used[l1 .. r1 + 1].any) {
                        used[l0 .. r0 + 1] = true;
                        set[i] = true;
                        flag = true;
                    } else {
                        if (flag) continue;
                        used[l0 .. r0 + 1] = true;
                        set[i] = true;
                        flag = true;
                    }
                }
            }
        }
        return true;
    }
    writeln(solve() ? "YES" : "NO");

}
0