結果
問題 | No.440 2次元チワワ問題 |
ユーザー | t8m8⛄️ |
提出日時 | 2016-11-05 20:08:56 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 936 ms / 5,000 ms |
コード長 | 1,897 bytes |
コンパイル時間 | 3,400 ms |
コンパイル使用メモリ | 69,212 KB |
実行使用メモリ | 21,096 KB |
最終ジャッジ日時 | 2023-09-12 07:03:47 |
合計ジャッジ時間 | 11,341 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 30 ms
7,952 KB |
testcase_08 | AC | 88 ms
7,928 KB |
testcase_09 | AC | 154 ms
11,752 KB |
testcase_10 | AC | 25 ms
6,640 KB |
testcase_11 | AC | 37 ms
4,904 KB |
testcase_12 | AC | 44 ms
14,164 KB |
testcase_13 | AC | 195 ms
20,804 KB |
testcase_14 | AC | 7 ms
4,376 KB |
testcase_15 | AC | 189 ms
21,096 KB |
testcase_16 | AC | 26 ms
5,180 KB |
testcase_17 | AC | 304 ms
19,892 KB |
testcase_18 | AC | 304 ms
19,916 KB |
testcase_19 | AC | 306 ms
19,916 KB |
testcase_20 | AC | 276 ms
19,928 KB |
testcase_21 | AC | 924 ms
19,940 KB |
testcase_22 | AC | 923 ms
19,880 KB |
testcase_23 | AC | 921 ms
19,864 KB |
testcase_24 | AC | 925 ms
19,904 KB |
testcase_25 | AC | 936 ms
19,912 KB |
ソースコード
{.optimization: speed.} import strutils, sequtils proc calc(H, W, Q: int, s: seq[seq[char]], q: seq[(int, int, int, int)], ans: var seq[int64]) = var c = newSeqWith(H+1, newSeq[int64](W+2)) cw = newSeqWith(H+1, newSeq[int64](W+2)) cww = newSeqWith(H+1, newSeq[int64](W+2)) wc = newSeqWith(H+1, newSeq[int64](W+2)) wwc = newSeqWith(H+1, newSeq[int64](W+2)) for h in 1..H: for w in 1..W: c[h][w] += c[h][w-1] cw[h][w] += cw[h][w-1] cww[h][w] += cww[h][w-1] if s[h-1][w-1] == 'c': c[h][w] += 1 if s[h-1][w-1] == 'w': cw[h][w] += c[h][w-1] cww[h][w] += cw[h][w-1] var rc = 0 for w in countDown(W, 1): wc[h][w] += wc[h][w+1] wwc[h][w] += wwc[h][w+1] if s[h-1][w-1] == 'w': wc[h][w] += rc wwc[h][w] += wc[h][w+1] if s[h-1][w-1] == 'c': rc += 1 for k in 0..Q-1: var (y1, x1, y2, x2) = q[k] for i in y1..y2: var ccnt = c[i][x2] - c[i][x1-1] wcnt = x2 - x1 + 1 - ccnt ans[k] += cww[i][x2] - cww[i][x1-1] ans[k] += wwc[i][x1] - wwc[i][x2+1] ans[k] -= (c[i][W] - ccnt)*wcnt*(wcnt-1) div 2 ans[k] -= wcnt*(cw[i][x1-1] + wc[i][x2+1]) when isMainModule: var tmp = stdin.readline.split.map(parseint) (H, W) = (tmp[0], tmp[1]) s = newSeqWith(H, newSeq[char](W)) s2 = newSeqWith(W, newSeq[char](H)) for i in 0..H-1: var t = stdin.readline for j in 0..W-1: s[i][j] = t[j] s2[j][i] = t[j] var Q = stdin.readline.parseint q: seq[(int, int, int, int)] = @[] q2: seq[(int, int, int, int)] = @[] for i in 0..Q-1: var tmp = stdin.readline.split.map(parseint) q.add((tmp[0], tmp[1], tmp[2], tmp[3])) q2.add((tmp[1], tmp[0], tmp[3], tmp[2])) var ans = newSeq[int64](Q) calc(H, W, Q, s, q, ans) calc(W, H, Q, s2, q2, ans) for i in ans: i.echo