結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | te-sh |
提出日時 | 2018-04-18 15:44:51 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,614 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 107,904 KB |
実行使用メモリ | 221,548 KB |
最終ジャッジ日時 | 2024-06-13 00:36:03 |
合計ジャッジ時間 | 24,186 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 1 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,944 KB |
ソースコード
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}} alias point = Point!int; void main() { int n, k, p; readV(n, k, p); point[] b; readS(k, b); foreach (ref bi; b) { --bi.x; --bi.y; } if (n == 1) { writeln(0); return; } auto a = kaidan!int(n); foreach (i; 0..n) a[i][] = -1; auto q = DList!point(b), dp = [point(-1, -1), point(-1, 0), point(0, -1), point(0, 1), point(1, 0), point(1, 1)]; foreach (ref bi; b) a[bi.x][bi.y] = 0; while (!q.empty) { auto pp = q.front; q.removeFront; foreach (dpi; dp) { auto np = pp + dpi; if (np.x < 0 || np.x >= n || np.y < 0 || np.y > np.x || a[np.x][np.y] >= 0) continue; a[np.x][np.y] =a[pp.x][pp.y] + 1; q.insertBack(np); } } auto as = kaidan!int(n+1); foreach_reverse (i; 0..n) foreach (j; 0..i+1) { as[i][j] = as[i+1][j] + as[i+1][j+1] + a[i][j]; if (i < n-1) as[i][j] -= as[i+2][j+1]; } auto bs = kaidan!int(n+1); foreach_reverse (i; 0..n) { bs[i] ~= 0; foreach (j; 0..i+2) bs[i][j+1] = bs[i][j]+bs[i+1][j+1]-bs[i+1][j]+a[i][j]; } auto calc(int i, int j, int e) { return as[i][j] - as[i+e+1][j+e+1] - bs[i+e+1][j+e+1] + bs[i+e+1][j]; } auto e = kaidan!int(n-1); foreach (j; 0..n-1) e[n-2][j] = as[n-2][j] >= p ? 1 : 2; foreach_reverse (i; 0..n-2) foreach (j; 0..i+1) { auto r = min(e[i+1][j], e[i+1][j+1]); while (calc(i, j, r) >= p && r >= 1) --r; e[i][j] = r+1; } auto ans = 0; foreach (i; 0..n-1) foreach (j; 0..i+1) ans += n-(e[i][j]+i); writeln(ans); } auto kaidan(T)(int n) { auto a = new T[][](n); foreach (i; 0..n) a[i] = new T[](i+1); return a; } struct Point(T) { T x, y; pure auto opBinary(string op)(Point!T r) if (op == "+" || op == "-") { return mixin("Point!T(x"~op~"r.x,y"~op~"r.y)"); } pure auto opBinary(string op)(T a) if (op == "*" || op == "/") { return mixin("Point!T(x"~op~"a,y"~op~"a)"); } auto opOpAssign(string op)(Point!T r) if (op == "+" || op == "-") { mixin("x"~op~"=r.x; y"~op~"=r.y;"); return this; } auto opOpAssign(string op)(T a) if (op == "*" || op == "/") { mixin("x"~op~"=a; y"~op~"=a;"); return this; } pure auto opBinary(string op: "*")(Point!T r) { return x*r.x + y*r.y; } pure auto hypot2() const { return x^^2 + y^^2; } }