結果

問題 No.655 E869120 and Good Triangles
ユーザー ふっぴーふっぴー
提出日時 2018-02-26 00:43:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,679 ms / 2,500 ms
コード長 3,009 bytes
コンパイル時間 3,071 ms
コンパイル使用メモリ 174,196 KB
実行使用メモリ 379,136 KB
最終ジャッジ日時 2024-04-18 10:03:18
合計ジャッジ時間 31,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1,641 ms
379,008 KB
testcase_11 AC 1,558 ms
379,084 KB
testcase_12 AC 1,576 ms
378,880 KB
testcase_13 AC 1,589 ms
379,008 KB
testcase_14 AC 1,582 ms
379,008 KB
testcase_15 AC 1,570 ms
378,960 KB
testcase_16 AC 1,679 ms
378,880 KB
testcase_17 AC 1,660 ms
379,008 KB
testcase_18 AC 1,658 ms
378,984 KB
testcase_19 AC 1,580 ms
379,136 KB
testcase_20 AC 1,603 ms
378,880 KB
testcase_21 AC 1,641 ms
379,008 KB
testcase_22 AC 1,536 ms
378,992 KB
testcase_23 AC 1,575 ms
379,008 KB
testcase_24 AC 1,053 ms
378,880 KB
testcase_25 AC 994 ms
378,752 KB
testcase_26 AC 992 ms
378,880 KB
testcase_27 AC 1,081 ms
378,752 KB
testcase_28 AC 958 ms
378,752 KB
testcase_29 AC 1,083 ms
378,752 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;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
//int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
int dx[6] = { 0, 1, 1, 0, -1, -1 }, dy[6] = { 1, 1, 0, -1, -1, 0 };

int main() {
	ll n, k, p;
	cin >> n >> k >> p;
	vll a(n, vl(n, INF));
	vi x(n), y(n);
	queue<pii> que;
	rep(i, k) {
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
		a[x[i]][y[i]] = 0;
		que.push(pii(x[i], y[i]));
	}
	while (!que.empty()) {
		pii now = que.front();
		que.pop();
		int i0 = now.first, j0 = now.second;
		int d = a[i0][j0];
		rep(i, 6) {
			int in = i0 + dx[i], jn = j0 + dy[i];
			if (in < 0 || in >= n || jn < 0 || jn >= n) {
				continue;
			}
			if (jn > in) {
				continue;
			}
			if (a[in][jn] > d + 1) {
				a[in][jn] = d + 1;
				que.push(pii(in, jn));
			}
		}
	}

	
	vll rnaname(n, vl(n + 1)), lnaname(n, vl(n + 1));
	rep(i, n) {
		rnaname[i][0] = 0;
		for (int j = i; j < n; j++) {
			rnaname[i][j + 1] = rnaname[i][j] + a[j][j - i];
		}
	}
	rep(i, n) {
		lnaname[i][0] = 0;
		for (int j = i; j < n; j++) {
			lnaname[i][j + 1] = lnaname[i][j] + a[j][i];
		}
	}
	/*
	rep(i, n) {
		rep(j, n) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	rep(i, n) {
		rep(j, n + 1) {
			cout << rnaname[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	rep(i, n) {
		rep(j, n + 1) {
			cout << lnaname[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	//*/
	ll ans = 0;
	rep(i, n) {
		//DEBUG(i);
		ll l = 0, r = 1;
		ll score = a[i][0];
		bool pre = false;
		bool first = true;
		while (true) {
			//printf("l: %d, r: %d, score: %d \n", l, r, score);
			if (score >= p) {
				if (first) {
					ans += (l + 1) * (i - r + 2);
					first = false;
				}
				else {
					ans += (i - r + 2);
				}
				/*
				cout << '-' << endl;
				DEBUG(i + 1);
				DEBUG(i - r + l);
				//*/
				score -= (lnaname[l][i + 1] - lnaname[l][i - (r - 1 - l)]);
				l++;
				pre = true;
			}
			else {
				if (r > i) {
					break;
				}
				/*
				cout << '+' << endl;
				DEBUG(i + 1);
				DEBUG(i - (r - l));
				//*/
				score += (rnaname[i - r][i + 1] - rnaname[i - r][i - (r - l)]);
				r++;
				pre = false;
			}
			//DEBUG(ans);
		}
		//printf("l: %d, r: %d, score: %d\n", l, r, score);
	}
	cout << ans << endl;
}
0