結果

問題 No.655 E869120 and Good Triangles
ユーザー FF256grhyFF256grhy
提出日時 2019-11-23 12:00:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,678 ms / 2,500 ms
コード長 3,462 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 177,624 KB
実行使用メモリ 316,672 KB
最終ジャッジ日時 2024-04-19 14:32:43
合計ジャッジ時間 31,452 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1,678 ms
316,416 KB
testcase_11 AC 1,549 ms
316,424 KB
testcase_12 AC 1,554 ms
316,544 KB
testcase_13 AC 1,554 ms
316,672 KB
testcase_14 AC 1,519 ms
316,416 KB
testcase_15 AC 1,575 ms
316,560 KB
testcase_16 AC 1,659 ms
316,544 KB
testcase_17 AC 1,603 ms
316,544 KB
testcase_18 AC 1,590 ms
316,456 KB
testcase_19 AC 1,608 ms
316,544 KB
testcase_20 AC 1,633 ms
316,416 KB
testcase_21 AC 1,599 ms
316,544 KB
testcase_22 AC 1,531 ms
316,544 KB
testcase_23 AC 1,519 ms
316,544 KB
testcase_24 AC 1,049 ms
316,288 KB
testcase_25 AC 993 ms
316,288 KB
testcase_26 AC 994 ms
316,416 KB
testcase_27 AC 1,090 ms
316,160 KB
testcase_28 AC 983 ms
316,160 KB
testcase_29 AC 1,055 ms
316,288 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)

// ---- ----

#define T0(T) T
#define T1(T) vector<T0(T)>
#define T2(T) vector<T1(T)>
#define V0(v, T,    ...) v
#define V1(v, T, n, ...) T1(T)(n, V0(v, T, __VA_ARGS__))
#define V2(v, T, n, ...) T2(T)(n, V1(v, T, __VA_ARGS__))

int main() {
	LL n, k, p;
	cin >> n >> k >> p;
	auto d = V2(n, int, n, 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);
		}
	}
	
	auto s1 = V2(0, LL, n + 1, n + 1);
	auto s2 = V2(0, LL, n + 1, n + 1);
	inc(i, n) {
	inc(j, n) {
		s1[i][j + 1] = d[i][j];
		s2[i + 1][j] = d[i][j];
	}
	}
	incII(i, 0, n) {
	incII(j, 0, n) {
		if(j > 0) { s1[i][j] += s1[i][j - 1]; }
		if(i > 0) { s2[i][j] += s2[i - 1][j]; }
	}
	}
	inc1(c, n) {
		inc1(j, c) { int i = c - j; s1[i][j] += s1[i + 1][j - 1]; }
		inc1(i, c) { int j = c - i; s2[i][j] += s2[i - 1][j + 1]; }
	}
	auto sum = [&](int c, int i, int j) -> LL {
		assert(s1[0][c    ] == s2[c    ][0]);
		assert(s1[0][i + j] == s2[i + j][0]);
		return s1[i][c - i] + s2[c - j][j] - s1[i][j] - s2[i][j] + s1[0][i + j] - s1[0][c];
	};
	
	LL ans = 0;
	inc1(c, n) {
		int j = c;
		incII(i, 0, c) {
			while(j >= 0 && sum(c, i, j) < p) { j--; }
			ans += j + 1;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
0