結果

問題 No.655 E869120 and Good Triangles
ユーザー hogethoget
提出日時 2018-02-23 23:43:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,009 ms / 2,500 ms
コード長 1,927 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 172,584 KB
実行使用メモリ 384,084 KB
最終ジャッジ日時 2023-07-31 08:45:31
合計ジャッジ時間 20,953 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,332 KB
testcase_01 AC 2 ms
5,452 KB
testcase_02 AC 2 ms
5,468 KB
testcase_03 AC 2 ms
5,412 KB
testcase_04 AC 2 ms
5,416 KB
testcase_05 AC 2 ms
5,372 KB
testcase_06 AC 2 ms
5,360 KB
testcase_07 AC 2 ms
5,416 KB
testcase_08 AC 2 ms
5,332 KB
testcase_09 AC 2 ms
5,456 KB
testcase_10 AC 1,009 ms
383,876 KB
testcase_11 AC 954 ms
383,076 KB
testcase_12 AC 958 ms
383,044 KB
testcase_13 AC 951 ms
383,980 KB
testcase_14 AC 972 ms
384,084 KB
testcase_15 AC 971 ms
384,032 KB
testcase_16 AC 987 ms
383,688 KB
testcase_17 AC 954 ms
383,912 KB
testcase_18 AC 954 ms
382,732 KB
testcase_19 AC 931 ms
383,988 KB
testcase_20 AC 949 ms
383,948 KB
testcase_21 AC 950 ms
383,964 KB
testcase_22 AC 914 ms
383,716 KB
testcase_23 AC 915 ms
383,652 KB
testcase_24 AC 629 ms
379,784 KB
testcase_25 AC 606 ms
380,068 KB
testcase_26 AC 606 ms
379,832 KB
testcase_27 AC 646 ms
380,000 KB
testcase_28 AC 588 ms
379,848 KB
testcase_29 AC 607 ms
379,872 KB
testcase_30 AC 2 ms
5,404 KB
testcase_31 AC 2 ms
5,356 KB
testcase_32 AC 2 ms
5,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={-1,-1,0,0,1,1},dy[]={-1,0,-1,1,0,1};

int num[4010][4010],d[4010][4010],a[4010][4010],b[4010][4010];

signed main(){
	int n,k,p,ans = 0;
	cin >> n >> k >> p;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= i;j++) d[i][j] = INF;
	}
	queue<P> que;
	for(int i = 0;i < k;i++){
		int x,y;
		cin >> x >> y;
		d[x][y] = 0;
		que.push(mp(x,y));
	}
	for(int t = 0;;t++){
		int siz = que.size();
		if(!siz) break;
		for(int i = 0;i < siz;i++){
			P p = que.front();que.pop();
			for(int j = 0;j < 6;j++){
				int nx = p.first + dx[j],ny = p.second + dy[j];
				if(nx >= 1 && ny >= 1 && nx <= n && ny <= nx && d[nx][ny] == INF){
					d[nx][ny] = t + 1;
					que.push(P(nx,ny));
				}
			}
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + d[i][j];
			b[i][j] = b[i - 1][j - 1] + a[i][j] - a[i][j - 1];
		}
	}
	for(int i = 1;i <= n;i++){
		int lst = 0;
		for(int j = i;j <= n;j++){
			while(j + lst <= n && a[lst + j][i + lst] - b[lst + j - 1][i + lst] - a[lst + j][i - 1] + (j >= 2 ? b[j - 2][i - 1] : 0) < p) lst++;
			ans += n - j - --lst;
		}
	}
	cout << ans << endl;
	return 0;
}
0