結果

問題 No.655 E869120 and Good Triangles
ユーザー FF256grhyFF256grhy
提出日時 2018-02-24 02:43:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,781 ms / 2,500 ms
コード長 3,457 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 176,320 KB
実行使用メモリ 256,228 KB
最終ジャッジ日時 2023-07-31 09:16:52
合計ジャッジ時間 36,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
253,264 KB
testcase_01 AC 180 ms
253,664 KB
testcase_02 AC 180 ms
253,740 KB
testcase_03 AC 182 ms
253,220 KB
testcase_04 AC 181 ms
253,212 KB
testcase_05 AC 179 ms
253,328 KB
testcase_06 AC 180 ms
253,228 KB
testcase_07 AC 179 ms
253,228 KB
testcase_08 AC 179 ms
253,080 KB
testcase_09 AC 178 ms
253,648 KB
testcase_10 AC 1,702 ms
256,032 KB
testcase_11 AC 1,617 ms
255,904 KB
testcase_12 AC 1,681 ms
255,748 KB
testcase_13 AC 1,662 ms
255,996 KB
testcase_14 AC 1,616 ms
255,940 KB
testcase_15 AC 1,679 ms
255,732 KB
testcase_16 AC 1,733 ms
255,796 KB
testcase_17 AC 1,781 ms
255,916 KB
testcase_18 AC 1,755 ms
256,212 KB
testcase_19 AC 1,714 ms
256,228 KB
testcase_20 AC 1,724 ms
255,764 KB
testcase_21 AC 1,717 ms
255,968 KB
testcase_22 AC 1,645 ms
255,912 KB
testcase_23 AC 1,656 ms
255,876 KB
testcase_24 AC 1,083 ms
253,832 KB
testcase_25 AC 1,081 ms
253,776 KB
testcase_26 AC 1,076 ms
253,764 KB
testcase_27 AC 1,144 ms
253,764 KB
testcase_28 AC 1,049 ms
253,740 KB
testcase_29 AC 1,122 ms
253,748 KB
testcase_30 AC 179 ms
253,080 KB
testcase_31 AC 181 ms
253,076 KB
testcase_32 AC 190 ms
253,084 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(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int 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 inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(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 PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

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; } }
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 V2(T, x, y) (x, vector<T>(y, 0))
template<typename T> struct Sum2 {
	typedef vector<vector<T>> A;
	// A s;
	int X, Y;
	Sum2() { X = Y = -1; }
	Sum2(A & p) { init(p); }
	void init(A & s, int X, int Y) {
		// X = s.size();
		// Y = s[0].size();
		// s = A V2(T, X + 1, Y + 1);
		// dec1(x, X) { dec1(y, Y) { s[x][y]  = s[x - 1][y - 1]; } }
		// inc(x, X + 1) { s[x][0] = 0; }
		// inc(y, Y + 1) { s[0][y] = 0; }
		inc1(x, X) { inc1(y, Y) { s[x][y] += s[x - 1][y    ]; } }
		inc1(x, X) { inc1(y, Y) { s[x][y] += s[x    ][y - 1]; } }
	}
	T sum(A & s, int xl, int xh, int yl, int yh) { // [xl, xh) × [yl, yh)
		/*
		assert(inII(xl, 0, X));
		assert(inII(xh, 0, X + 1));
		assert(inII(yl, 0, Y));
		assert(inII(yh, 0, Y + 1));
		assert(xl <= xh);
		assert(yl <= yh);
		*/
		return s[xh][yh] - s[xh][yl] - s[xl][yh] + s[xl][yl];
	}
};

// ----

LL n, k, p, x[4000], y[4000];
vector<vector<LL>> a V2(LL, 4001, 4001);
vector<vector<LL>> b V2(LL, 4001, 4001);
Sum2<LL> sa, sb;

LL f(int i, int j, int l) {
	return sb.sum(b, i, l, 0, j + n - i) - sa.sum(a, i, l, 0, j);
}

int main() {
	cin >> n >> k >> p;
	inc(i, k) { cin >> x[i] >> y[i]; }
	
	inc(i, n) {
	incII(j, 0, i) {
		a[i + 1][j + 1] = n;
	}
	}
	queue<pair<int, int>> q;
	inc(i, k) {
		a[x[i]][y[i]] = 0;
		q.push(MP(x[i], y[i]));
	}
	while(! q.empty()) {
		auto e = q.front(); q.pop();
		int dx[6] = { +1,  0, -1,  0, +1, -1 };
		int dy[6] = {  0, +1,  0, -1, +1, -1 };
		inc(l, 6) {
			int xx = e.FI + dx[l];
			int yy = e.SE + dy[l];
			if(inII(xx, 1, n) && inII(yy, 1, n)) { } else { continue; }
			if(setmin(a[xx][yy], a[e.FI][e.SE] + 1)) { q.push(MP(xx, yy)); }
		}
	}
	
	inc(i, n) {
	incII(j, 0, i) {
		b[i + 1][j + (n - 1 - i) + 1] = a[i + 1][j + 1];
	}
	}
	
	sa.init(a, n, n);
	sb.init(b, n, n);
	
	LL ans = 0;
	inc1(v, n) { int L = n;
	dec(j, v) {
		int i = n - v + j;
		while(f(i, j, L) >= p) { L--; }
		ans += n - L;
	}
	}
	
	cout << ans << endl;
	
	return 0;
}
0