結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | te-sh |
提出日時 | 2017-06-19 15:36:00 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 2,377 ms / 4,000 ms |
コード長 | 3,254 bytes |
コンパイル時間 | 977 ms |
コンパイル使用メモリ | 128,800 KB |
実行使用メモリ | 13,220 KB |
最終ジャッジ日時 | 2024-06-12 20:15:21 |
合計ジャッジ時間 | 13,107 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,948 KB |
testcase_04 | AC | 3 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 19 ms
6,944 KB |
testcase_08 | AC | 133 ms
11,444 KB |
testcase_09 | AC | 50 ms
8,004 KB |
testcase_10 | AC | 6 ms
6,940 KB |
testcase_11 | AC | 14 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 35 ms
6,948 KB |
testcase_14 | AC | 6 ms
6,944 KB |
testcase_15 | AC | 10 ms
6,944 KB |
testcase_16 | AC | 10 ms
6,940 KB |
testcase_17 | AC | 112 ms
10,652 KB |
testcase_18 | AC | 371 ms
11,364 KB |
testcase_19 | AC | 310 ms
11,364 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 222 ms
11,472 KB |
testcase_22 | AC | 185 ms
11,476 KB |
testcase_23 | AC | 2,175 ms
11,300 KB |
testcase_24 | AC | 783 ms
13,220 KB |
testcase_25 | AC | 1,094 ms
11,396 KB |
testcase_26 | AC | 2,362 ms
12,984 KB |
testcase_27 | AC | 36 ms
6,940 KB |
testcase_28 | AC | 120 ms
12,752 KB |
testcase_29 | AC | 25 ms
6,944 KB |
testcase_30 | AC | 2,377 ms
11,408 KB |
testcase_31 | AC | 60 ms
6,940 KB |
testcase_32 | AC | 49 ms
6,940 KB |
testcase_33 | AC | 31 ms
6,944 KB |
testcase_34 | AC | 48 ms
6,940 KB |
testcase_35 | AC | 54 ms
6,940 KB |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.container; // SList, DList, BinaryHeap alias Point!int point; alias Grid!(int, int) grid; void main() { auto rd1 = readln.split.to!(size_t[]), h = rd1[0], w = rd1[1]; auto a = h.iota.map!(_ => readln.split.to!(int[])).array; auto g = grid(a); auto q = readln.chomp.to!size_t, sameColor = false, lastColor = 0; foreach (_; 0..q) { auto rd2 = readln.split.to!(int[]), p = point(rd2[1]-1, rd2[0]-1), x = rd2[2]; if (sameColor) { lastColor = x; continue; } if (g[p] == x) continue; g[p] = x; auto qu = new DList!point([p]), cnt = 1; while (!qu.empty) { auto qp = qu.front; qu.removeFront(); foreach (np; g.sibPoints4(qp)) if (g[np] != x) { g[np] = x; qu.insertBack(np); ++cnt; } } if (cnt == h * w) { sameColor = true; lastColor = x; } } if (sameColor) { foreach (i; 0..h) writeln(lastColor.repeat.take(w).array.to!(string[]).join(" ")); } else { foreach (i; 0..h) writeln(g[i].to!(string[]).join(" ")); } } struct Point(T) { T x, y; pure auto opBinary(string op: "+")(Point!T rhs) const { return Point!T(x + rhs.x, y + rhs.y); } pure auto opBinary(string op: "-")(Point!T rhs) const { return Point!T(x - rhs.x, y - rhs.y); } pure auto opBinary(string op: "*")(Point!T rhs) const { return x * rhs.x + y * rhs.y; } pure auto opBinary(string op: "*")(T a) const { return Point!T(x * a, y * a); } pure auto opBinary(string op: "/")(T a) const { return Point!T(x / a, y / a); } pure auto hypot2() const { return x ^^ 2 + y ^^ 2; } } struct Grid(T, U) { import std.algorithm, std.conv, std.range, std.traits, std.typecons; const sibs4 = [Point!U(-1, 0), Point!U(0, -1), Point!U(1, 0), Point!U(0, 1)]; const sibs8 = [Point!U(-1, 0), Point!U(-1, -1), Point!U(0, -1), Point!U(1, -1), Point!U(1, 0), Point!U(1, 1), Point!U(0, 1), Point!U(-1, 1)]; T[][] m; const size_t rows, cols; mixin Proxy!m; this(size_t r, size_t c) { rows = r; cols = c; m = new T[][](rows, cols); } this(T[][] s) { rows = s.length; cols = s[0].length; m = s; } pure auto dup() const { return Grid(m.map!(r => r.dup).array); } ref pure auto opIndex(Point!U p) { return m[p.y][p.x]; } ref pure auto opIndex(size_t y) { return m[y]; } ref pure auto opIndex(size_t y, size_t x) const { return m[y][x]; } static if (isAssignable!T) { auto opIndexAssign(T v, Point!U p) { return m[p.y][p.x] = v; } auto opIndexAssign(T v, size_t y, size_t x) { return m[y][x] = v; } auto opIndexOpAssign(string op, V)(V v, Point!U p) { return mixin("m[p.y][p.x] " ~ op ~ "= v"); } auto opIndexOpAssign(string op, V)(V v, size_t y, size_t x) { return mixin("m[y][x] " ~ op ~ "= v"); } } pure auto validPoint(Point!U p) { return p.x >= 0 && p.x < cols && p.y >= 0 && p.y < rows; } pure auto points() const { return rows.to!U.iota.map!(y => cols.to!U.iota.map!(x => Point!U(x, y))).joiner; } pure auto sibPoints4(Point!U p) { return sibs4.map!(s => p + s).filter!(p => validPoint(p)); } pure auto sibPoints8(Point!U p) { return sibs8.map!(s => p + s).filter!(p => validPoint(p)); } }