結果

問題 No.655 E869120 and Good Triangles
ユーザー e869120e869120
提出日時 2018-01-28 13:25:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,336 ms / 2,500 ms
コード長 1,937 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 79,048 KB
実行使用メモリ 500,384 KB
最終ジャッジ日時 2024-04-18 09:02:47
合計ジャッジ時間 23,622 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1,336 ms
363,108 KB
testcase_11 AC 1,193 ms
363,904 KB
testcase_12 AC 1,247 ms
363,300 KB
testcase_13 AC 1,113 ms
363,648 KB
testcase_14 AC 1,102 ms
363,648 KB
testcase_15 AC 1,128 ms
363,120 KB
testcase_16 AC 1,128 ms
363,904 KB
testcase_17 AC 1,126 ms
363,904 KB
testcase_18 AC 1,145 ms
363,648 KB
testcase_19 AC 1,167 ms
363,648 KB
testcase_20 AC 1,138 ms
500,384 KB
testcase_21 AC 1,153 ms
363,904 KB
testcase_22 AC 1,089 ms
363,648 KB
testcase_23 AC 1,109 ms
363,904 KB
testcase_24 AC 780 ms
361,344 KB
testcase_25 AC 928 ms
361,600 KB
testcase_26 AC 905 ms
361,472 KB
testcase_27 AC 1,011 ms
361,728 KB
testcase_28 AC 904 ms
361,600 KB
testcase_29 AC 846 ms
361,728 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

long long n, k, r, a[4009][4009], b[4009][4009], c[4009][4009], dp[4009][4009]; queue<pair<int, int>>Q;

long long sum(long long p, long long q, long long r) {
	long long res = c[p][q] - c[p + r][q + r] - (b[p + r][q + r - 1] - b[p + r][q - 1]);
	return res;
}

int main() {
	cin >> n >> k >> r;
	for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++)a[i][j] = (1 << 30); }
	for (int i = 1; i <= k; i++) {
		int x, y; cin >> x >> y;
		a[x][y] = 0; Q.push(make_pair(x, y));
	}
	while (!Q.empty()) {
		pair<int, int>a1 = Q.front(); Q.pop();
		int dx[6] = { -1,-1,0,0,1,1 }, dy[6] = { -1,0,-1,1,0,1 };
		for (int i = 0; i < 6; i++) {
			int cx = a1.first + dx[i], cy = a1.second + dy[i];
			if (cy <= 0 || cx > n || cx < cy) continue;
			if (a[cx][cy] > a[a1.first][a1.second] + 1) {
				a[cx][cy] = a[a1.first][a1.second] + 1;
				Q.push(make_pair(cx, cy));
			}
		}
	}
	for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++)b[i][j] = a[i][j]; }
	for (int i = 1; i <= n; i++) { for (int j = n - 1; j >= i; j--) b[j][i] += b[j + 1][i]; }
	for (int i = n; i >= 1; i--) {
		for (int j = i; j <= n; j++) {
			c[j][i] = c[j + 1][i + 1] + b[j][i];
		}
	}
	for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= n + 1; j++) b[i][j] = 0; }
	for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) b[i][j] = a[i][j]; }
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) b[i][j] += b[i][j - 1];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = n; j >= i; j--) b[j][i] += b[j + 1][i];
	}
	for (int i = 1; i <= n + 1; i++) dp[n + 1][i] = 1;
	long long ans = 0;
	for (int i = n; i >= 1; i--) {
		for (int j = i; j >= 1; j--) {
			long long G = min(dp[i + 1][j], dp[i + 1][j + 1]);
			while (true) {
				if (sum(i, j, G) < r) { dp[i][j] = G + 1; break; }
				G--;
			}
			ans += (n - i + 1) - dp[i][j] + 1;
		}
	}
	cout << ans << endl;
	return 0;
}
0