結果

問題 No.655 E869120 and Good Triangles
ユーザー FF256grhyFF256grhy
提出日時 2019-11-23 12:57:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 767 ms / 2,500 ms
コード長 3,084 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 170,516 KB
実行使用メモリ 224,128 KB
最終ジャッジ日時 2024-04-19 14:38:35
合計ジャッジ時間 14,265 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 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 695 ms
224,128 KB
testcase_11 AC 657 ms
223,468 KB
testcase_12 AC 657 ms
223,724 KB
testcase_13 AC 626 ms
224,000 KB
testcase_14 AC 747 ms
224,000 KB
testcase_15 AC 698 ms
223,184 KB
testcase_16 AC 711 ms
223,488 KB
testcase_17 AC 662 ms
223,872 KB
testcase_18 AC 717 ms
223,888 KB
testcase_19 AC 657 ms
223,872 KB
testcase_20 AC 767 ms
223,872 KB
testcase_21 AC 668 ms
224,000 KB
testcase_22 AC 642 ms
224,000 KB
testcase_23 AC 636 ms
224,000 KB
testcase_24 AC 407 ms
221,696 KB
testcase_25 AC 389 ms
221,696 KB
testcase_26 AC 402 ms
221,696 KB
testcase_27 AC 418 ms
221,824 KB
testcase_28 AC 365 ms
221,696 KB
testcase_29 AC 400 ms
221,824 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

const int N = 4000;
int d[N][N];
LL s1[N + 1][N + 1];
LL s2[N + 1][N + 1];

int main() {
	LL n, k, p;
	cin >> n >> k >> p;
	inc(i, n) {
	inc(j, n) {
		d[i][j] = n;
	}
	}
	queue<pair<int, int>> q;
	auto update = [&](int i, int j, int v) {
		if(setmin(d[i][j], v)) { q.push({ i, j }); }
	};
	inc(l, k) {
		int i, j;
		cin >> i >> j;
		i--; j--;
		i = n - 1 - i;
		update(i, j, 0);
	}
	while(! q.empty()) {
		auto e = q.front(); q.pop();
		int i = e.FI;
		int j = e.SE;
		inc(l, 6) {
			int di[6] = { +1,  0, -1,  0, +1, -1 };
			int dj[6] = {  0, +1,  0, -1, -1, +1 };
			int ii = i + di[l];
			int jj = j + dj[l];
			if(! (0 <= ii && 0 <= jj && ii + jj < n)) { continue; }
			update(ii, jj, d[i][j] + 1);
		}
	}
	
	inc(i, n) {
	inc(j, n) {
		if(i + j >= n) { continue; }
		s1[i][j + 1] = d[i][j];
		s2[i + 1][j] = d[i][j];
	}
	}
	incII(i, 0, n) {
	incII(j, 0, n) {
		if(i + j >  n) { continue; }
		if(j > 0) { s1[i][j] += s1[i][j - 1]; }
		if(i > 0) { s2[i][j] += s2[i - 1][j]; }
	}
	}
	
	LL ans = 0;
	inc1(c, n) {
		int j = c;
		LL sum = 0;
		incII(i, 0, c) {
			while(sum < p) { j--; if(j < 0) { break; } sum += s2[c - j][j] - s2[i][j]; }
			if(j < 0) { break; }
			ans += j + 1;
			sum -= s1[i][c - i] - s1[i][j];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
0