結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-05-02 16:53:58 |
言語 | D (dmd 2.106.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,665 bytes |
コンパイル時間 | 983 ms |
コンパイル使用メモリ | 120,400 KB |
実行使用メモリ | 580,388 KB |
最終ジャッジ日時 | 2024-06-22 01:08:19 |
合計ジャッジ時間 | 31,567 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | AC | 1 ms
6,944 KB |
testcase_31 | AC | 1 ms
6,944 KB |
testcase_32 | AC | 1 ms
6,940 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)); } /* 00 10 01 20 11 02 30 21 12 03 */ int N, K; long P; int[] X, Y; int[][] D; void bfs() { auto q = new int[N * (N + 1)]; int qHead, qTail; D = new int[][](N, N); foreach (x; 0 .. N) foreach (y; 0 .. N) { if (x + y < N) { D[x][y] = 2 * N; } } foreach (k; 0 .. K) { D[X[k]][Y[k]] = 0; q[qTail++] = X[k]; q[qTail++] = Y[k]; } for (; qHead != qTail; ) { const x = q[qHead++]; const y = q[qHead++]; void update(int xx, int yy) { if (D[xx][yy] > D[x][y] + 1) { D[xx][yy] = D[x][y] + 1; q[qTail++] = xx; q[qTail++] = yy; } } if (x + y + 1 < N) { update(x + 1, y); update(x, y + 1); } if (x - 1 >= 0) { update(x - 1, y + 1); update(x - 1, y); } if (y - 1 >= 0) { update(x, y - 1); update(x + 1, y - 1); } } } void main() { try { for (; ; ) { N = readInt(); K = readInt(); P = readLong(); X = new int[K]; Y = new int[K]; foreach (k; 0 .. K) { X[k] = readInt() - 1; Y[k] = readInt() - 1; X[k] -= Y[k]; } bfs(); // rectangle headed at (0, 0) auto r = new long[][](N + 1, N + 1); foreach (x; 0 .. N) foreach (y; 0 .. N) { r[x + 1][y + 1] = r[x][y + 1] + r[x + 1][y] - r[x][y] + D[x][y]; } // D[z][0] + ... + D[0][z] auto s = new long[][](N, N + 1); foreach (z; 0 .. N) { foreach (y; 0 .. z + 1) { s[z][y + 1] = s[z][y] + D[z - y][y]; } } // triangles headed at (x, 0) auto tX = new long[][](N, N + 1); foreach (x; 0 .. N) { foreach (l; 0 .. N - x) { tX[x][l + 1] = tX[x][l] + (s[x + l][l + 1] - s[x + l][0]); } } // triangles headed at (0, y) auto tY = new long[][](N, N + 1); foreach (y; 0 .. N) { foreach (l; 0 .. N - y) { tY[y][l + 1] = tY[y][l] + (s[y + l][y + l + 1] - s[y + l][y]); } } debug { foreach (z; 0 .. N) { write(' '.repeat(N - z)); foreach (y; 0 .. z + 1) { write(D[z - y][y], " "); } writeln(); } writeln("r = ", r); writeln("s = ", s); writeln("tX = ", tX); writeln("tY = ", tY); } long ans; /* foreach (x; 0 .. N) foreach (y; 0 .. N) { if (x + y < N) { int lo = 0, hi = N - (x + y) + 1; for (; lo + 1 < hi; ) { const mid = (lo + hi) / 2; const sum = r[x][y] + tX[x][mid + y] + tY[y][mid + x] - tX[0][mid + x + y]; (sum >= P) ? (hi = mid) : (lo = mid); } ans += (N - (x + y) + 1) - hi; } } */ long getSum(int z, int y0, int y1) { const l = y1 - y0; if (l <= 0) { return 0; } const x = z - (l - 1) - y0; const y = y0; debug { // writeln("getSum ", z, " [", y0, ", ", y1, "); ", l, " ", x, " ", y); } return r[x][y] + tX[x][l + y] + tY[y][l + x] - tX[0][l + x + y]; } foreach (z; 0 .. N) { for (int y0 = 0, y1 = 0; y0 <= z; ++y0) { for (; y1 <= z + 1 && (y1 <= y0 || getSum(z, y0, y1) < P); ++y1) {} debug { writeln(z, " ", y0, " ", y1); } ans += z + 2 - y1; } } writeln(ans); } } catch (EOFException e) { } }