結果
問題 | No.1328 alligachi-problem |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-12-25 00:29:47 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 283 ms / 2,000 ms |
コード長 | 3,868 bytes |
コンパイル時間 | 959 ms |
コンパイル使用メモリ | 131,600 KB |
実行使用メモリ | 14,696 KB |
最終ジャッジ日時 | 2024-06-22 10:31:39 |
合計ジャッジ時間 | 9,748 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 4 ms
6,944 KB |
testcase_05 | AC | 5 ms
6,940 KB |
testcase_06 | AC | 3 ms
6,944 KB |
testcase_07 | AC | 5 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 283 ms
13,488 KB |
testcase_10 | AC | 179 ms
11,264 KB |
testcase_11 | AC | 277 ms
13,668 KB |
testcase_12 | AC | 278 ms
13,716 KB |
testcase_13 | AC | 271 ms
13,736 KB |
testcase_14 | AC | 264 ms
14,156 KB |
testcase_15 | AC | 175 ms
11,392 KB |
testcase_16 | AC | 262 ms
13,524 KB |
testcase_17 | AC | 259 ms
13,464 KB |
testcase_18 | AC | 272 ms
13,516 KB |
testcase_19 | AC | 266 ms
13,484 KB |
testcase_20 | AC | 264 ms
13,528 KB |
testcase_21 | AC | 277 ms
13,504 KB |
testcase_22 | AC | 267 ms
13,528 KB |
testcase_23 | AC | 175 ms
12,484 KB |
testcase_24 | AC | 176 ms
12,940 KB |
testcase_25 | AC | 172 ms
12,136 KB |
testcase_26 | AC | 233 ms
14,696 KB |
testcase_27 | AC | 231 ms
13,264 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, 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 readColor() { const input = readToken; return (input == "R") ? 0 : 1; } int N; int[] C, X, Y; int[] solve() { alias Entry = Tuple!(int, "y", int, "u"); auto esss = new Entry[][][](2, 2); foreach (u; 0 .. N) { esss[C[u]][X[u]] ~= Entry(Y[u], u); } foreach (c; 0 .. 2) { foreach (x; 0 .. 2) { esss[c][x].sort; } } debug { foreach (c; 0 .. 2) { foreach (x; 0 .. 2) { writefln("esss[%s][%s] = %s", c, x, esss[c][x]); } } } auto lens = new int[2]; foreach (c; 0 .. 2) { foreach (x; 0 .. 2) { lens[c] += cast(int)(esss[c][x].length); } } auto uss = new int[][2]; foreach (c; 0 .. 2) { uss[c] = new int[lens[c]]; uss[c][] = -1; foreach (ref e; esss[c][c]) { if (!(0 <= e.y && e.y < lens[c])) { return null; } if (uss[c][e.y] != -1) { return null; } uss[c][e.y] = e.u; } int pos; foreach (ref e; esss[c][c ^ 1]) { for (; uss[c][pos] != -1; ++pos) {} uss[c][pos] = e.u; } } debug { writeln("uss = ", uss); } auto mns = new int[lens[1]]; auto mxs = new int[lens[1]]; mns[] = 0; mxs[] = lens[0]; foreach (i0; 0 .. lens[0]) { const u = uss[0][i0]; if (X[u] == 1) { if (!(0 <= Y[u] && Y[u] <= lens[1])) { return null; } if (Y[u] - 1 >= 0) { chmin(mxs[Y[u] - 1], i0); } if (Y[u] < lens[1]) { chmax(mns[Y[u]], i0 + 1); } } } foreach (i1; 0 .. lens[1]) { const u = uss[1][i1]; if (X[u] == 0) { if (!(0 <= Y[u] && Y[u] <= lens[0])) { return null; } chmax(mns[i1], Y[u]); chmin(mxs[i1], Y[u]); } } auto vals = new int[lens[1]]; int bef = 0; foreach (i1; 0 .. lens[1]) { chmax(bef, mns[i1]); if (!(bef <= mxs[i1])) { return null; } vals[i1] = bef; } vals ~= lens[0]; debug { writeln("vals = ", vals); } int[] ans; { int i0; foreach (i1; 0 .. lens[1] + 1) { for (; i0 < vals[i1]; ++i0) { ans ~= uss[0][i0]; } if (i1 < lens[1]) { ans ~= uss[1][i1]; } } } return ans; } void main() { try { for (; ; ) { N = readInt(); C = new int[N]; X = new int[N]; Y = new int[N]; foreach (u; 0 .. N) { C[u] = readColor(); X[u] = readColor(); Y[u] = readInt(); } const ans = solve; if (ans) { writeln("Yes"); foreach (j; 0 .. N) { if (j > 0) write(" "); write(ans[j] + 1); } writeln; } else { writeln("No"); } } } catch (EOFException e) { } }