結果

問題 No.655 E869120 and Good Triangles
ユーザー square1001square1001
提出日時 2018-02-23 23:30:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 954 ms / 2,500 ms
コード長 1,260 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 33,020 KB
実行使用メモリ 220,692 KB
最終ジャッジ日時 2023-07-31 08:40:35
合計ジャッジ時間 18,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,100 KB
testcase_01 AC 2 ms
9,080 KB
testcase_02 AC 3 ms
9,120 KB
testcase_03 AC 3 ms
9,120 KB
testcase_04 AC 2 ms
9,132 KB
testcase_05 AC 3 ms
9,120 KB
testcase_06 AC 3 ms
9,080 KB
testcase_07 AC 3 ms
9,072 KB
testcase_08 AC 2 ms
9,116 KB
testcase_09 AC 2 ms
9,104 KB
testcase_10 AC 911 ms
220,624 KB
testcase_11 AC 895 ms
220,648 KB
testcase_12 AC 920 ms
220,528 KB
testcase_13 AC 916 ms
220,616 KB
testcase_14 AC 935 ms
220,628 KB
testcase_15 AC 921 ms
220,568 KB
testcase_16 AC 896 ms
220,628 KB
testcase_17 AC 947 ms
220,632 KB
testcase_18 AC 947 ms
220,496 KB
testcase_19 AC 954 ms
220,576 KB
testcase_20 AC 918 ms
220,532 KB
testcase_21 AC 929 ms
220,692 KB
testcase_22 AC 911 ms
220,560 KB
testcase_23 AC 908 ms
220,604 KB
testcase_24 AC 693 ms
220,600 KB
testcase_25 AC 683 ms
220,604 KB
testcase_26 AC 673 ms
220,628 KB
testcase_27 AC 697 ms
220,576 KB
testcase_28 AC 690 ms
220,580 KB
testcase_29 AC 676 ms
220,556 KB
testcase_30 AC 2 ms
9,024 KB
testcase_31 AC 2 ms
9,100 KB
testcase_32 AC 3 ms
9,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
int dx[] = { 0, 1, 0, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1 };
int N, K, x, y, l, r, qx[8002009], qy[8002009], v[4009][4009], sx[4009][4009], sy[4009][4009]; long long X;
int main() {
	scanf("%d %d %lld", &N, &K, &X);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - i; j++) {
			v[i][j] = -1;
		}
	}
	for (int i = 0; i < K; i++) {
		scanf("%d %d", &x, &y), x = x - y, y--;
		if (v[x][y] == -1) v[x][y] = 0, qx[r] = x, qy[r++] = y;
	}
	while (l != r) {
		x = qx[l], y = qy[l++];
		for (int i = 0; i < 6; i++) {
			int tx = x + dx[i], ty = y + dy[i];
			if (0 <= tx && tx < N && 0 <= ty && ty < N && 0 <= tx + ty && tx + ty < N && v[tx][ty] == -1) {
				v[tx][ty] = v[x][y] + 1;
				qx[r] = tx, qy[r++] = ty;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - i; j++) {
			sx[i][j + 1] = sx[i][j] + v[i][j];
			sy[i][j + 1] = sy[i][j] + v[j][i];
		}
	}
	long long ret = 0;
	for (int i = 0; i < N; i++) {
		int cx = i + 1; long long cs = 0;
		for (int j = 0; j <= i; j++) {
			while (cx != 0) {
				int delta = sy[cx - 1][i - cx + 2] - sy[cx - 1][j];
				if (cs + delta >= X) break;
				cs += delta;
				cx--;
			}
			ret += cx;
			cs -= sx[j][i - j + 1] - sx[j][cx];
		}
	}
	printf("%lld\n", ret);
	return 0;
}
0