結果
問題 | No.440 2次元チワワ問題 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-06-07 14:35:13 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 665 ms / 5,000 ms |
コード長 | 3,807 bytes |
コンパイル時間 | 913 ms |
コンパイル使用メモリ | 125,000 KB |
実行使用メモリ | 70,812 KB |
最終ジャッジ日時 | 2024-06-22 01:37:25 |
合計ジャッジ時間 | 9,015 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 45 ms
13,548 KB |
testcase_08 | AC | 112 ms
11,072 KB |
testcase_09 | AC | 266 ms
30,016 KB |
testcase_10 | AC | 45 ms
10,892 KB |
testcase_11 | AC | 32 ms
6,940 KB |
testcase_12 | AC | 83 ms
27,104 KB |
testcase_13 | AC | 325 ms
48,180 KB |
testcase_14 | AC | 5 ms
6,940 KB |
testcase_15 | AC | 302 ms
53,032 KB |
testcase_16 | AC | 15 ms
6,944 KB |
testcase_17 | AC | 506 ms
69,772 KB |
testcase_18 | AC | 496 ms
70,096 KB |
testcase_19 | AC | 511 ms
69,504 KB |
testcase_20 | AC | 495 ms
68,912 KB |
testcase_21 | AC | 657 ms
68,920 KB |
testcase_22 | AC | 657 ms
70,708 KB |
testcase_23 | AC | 665 ms
69,544 KB |
testcase_24 | AC | 662 ms
70,812 KB |
testcase_25 | AC | 639 ms
70,296 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, 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 H, W; string[] S; int Q; int[] A, B, C, D; void main() { try { for (; ; ) { H = readInt(); W = readInt(); S = new string[H]; foreach (x; 0 .. H) { S[x] = readToken(); } Q = readInt(); A = new int[Q]; B = new int[Q]; C = new int[Q]; D = new int[Q]; foreach (q; 0 .. Q) { A[q] = readInt() - 1; B[q] = readInt() - 1; C[q] = readInt(); D[q] = readInt(); } auto ans = new long[Q]; foreach (dir; 0 .. 2) { auto hor = new long[][][](H, W + 1, 3 + 1); foreach (x; 0 .. H) { hor[x][0][0] = 1; foreach (y; 0 .. W) { hor[x][y + 1][] = hor[x][y][]; foreach (k; 0 .. 3) { if (S[x][y] == "cww"[k]) { hor[x][y + 1][k + 1] += hor[x][y][k]; } } } } auto ver = new long[][][](H + 1, W, 3 + 1); foreach (y; 0 .. W) { ver[0][y][0] = 1; foreach (x; 0 .. H) { ver[x + 1][y][] = ver[x][y][]; foreach (k; 0 .. 3) { if (S[x][y] == "cww"[k]) { ver[x + 1][y][k + 1] += ver[x][y][k]; } } } } debug { writeln("hor = ", hor); writeln("ver = ", ver); } foreach (q; 0 .. Q) { foreach (x; A[q] .. C[q]) { const long w = (D[q] - B[q]) - (hor[x][D[q]][1] - hor[x][B[q]][1]); long tmp = hor[x][D[q]][3]; tmp -= hor[x][B[q]][3]; tmp -= hor[x][B[q]][2] * w; tmp -= hor[x][B[q]][1] * w * (w - 1) / 2; debug { writeln("x = ", x, ": ", tmp); } ans[q] += tmp; } foreach (y; B[q] .. D[q]) { const long w = (C[q] - A[q]) - (ver[C[q]][y][1] - ver[A[q]][y][1]); long tmp = ver[C[q]][y][3]; tmp -= ver[A[q]][y][3]; tmp -= ver[A[q]][y][2] * w; tmp -= ver[A[q]][y][1] * w * (w - 1) / 2; debug { writeln("y = ", y, ": ", tmp); } ans[q] += tmp; } } S.reverse; foreach (x; 0 .. H) { S[x] = S[x].dup.to!(char[]).reverse.to!string; } foreach (q; 0 .. Q) { swap(A[q], C[q]); swap(B[q], D[q]); A[q] = H - A[q]; C[q] = H - C[q]; B[q] = W - B[q]; D[q] = W - D[q]; } } foreach (q; 0 .. Q) { writeln(ans[q]); } } } catch (EOFException e) { } }