結果

問題 No.655 E869120 and Good Triangles
ユーザー square1001square1001
提出日時 2018-02-23 23:30:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 937 ms / 2,500 ms
コード長 1,260 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 34,688 KB
実行使用メモリ 230,304 KB
最終ジャッジ日時 2024-04-18 09:08:23
合計ジャッジ時間 17,683 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,064 KB
testcase_01 AC 3 ms
9,932 KB
testcase_02 AC 3 ms
9,800 KB
testcase_03 AC 2 ms
10,056 KB
testcase_04 AC 3 ms
10,060 KB
testcase_05 AC 3 ms
9,928 KB
testcase_06 AC 3 ms
9,932 KB
testcase_07 AC 3 ms
9,932 KB
testcase_08 AC 3 ms
10,056 KB
testcase_09 AC 3 ms
9,932 KB
testcase_10 AC 888 ms
228,208 KB
testcase_11 AC 838 ms
228,812 KB
testcase_12 AC 937 ms
229,080 KB
testcase_13 AC 874 ms
230,028 KB
testcase_14 AC 906 ms
229,508 KB
testcase_15 AC 905 ms
229,936 KB
testcase_16 AC 897 ms
230,096 KB
testcase_17 AC 876 ms
227,856 KB
testcase_18 AC 876 ms
227,944 KB
testcase_19 AC 833 ms
229,392 KB
testcase_20 AC 816 ms
227,888 KB
testcase_21 AC 871 ms
229,260 KB
testcase_22 AC 799 ms
227,768 KB
testcase_23 AC 786 ms
229,132 KB
testcase_24 AC 612 ms
227,892 KB
testcase_25 AC 599 ms
228,364 KB
testcase_26 AC 588 ms
228,696 KB
testcase_27 AC 622 ms
228,308 KB
testcase_28 AC 622 ms
227,588 KB
testcase_29 AC 616 ms
230,304 KB
testcase_30 AC 3 ms
9,928 KB
testcase_31 AC 3 ms
9,932 KB
testcase_32 AC 3 ms
9,932 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