結果

問題 No.655 E869120 and Good Triangles
ユーザー 👑 kmjpkmjp
提出日時 2018-02-23 23:21:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 936 ms / 2,500 ms
コード長 1,801 bytes
コンパイル時間 1,383 ms
コンパイル使用メモリ 166,908 KB
実行使用メモリ 223,744 KB
最終ジャッジ日時 2024-04-18 09:34:19
合計ジャッジ時間 16,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 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 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 936 ms
223,240 KB
testcase_11 AC 821 ms
223,744 KB
testcase_12 AC 819 ms
223,352 KB
testcase_13 AC 803 ms
223,744 KB
testcase_14 AC 832 ms
223,616 KB
testcase_15 AC 780 ms
222,968 KB
testcase_16 AC 780 ms
223,744 KB
testcase_17 AC 808 ms
223,744 KB
testcase_18 AC 795 ms
223,616 KB
testcase_19 AC 801 ms
223,744 KB
testcase_20 AC 824 ms
223,616 KB
testcase_21 AC 807 ms
223,744 KB
testcase_22 AC 815 ms
223,744 KB
testcase_23 AC 815 ms
223,744 KB
testcase_24 AC 532 ms
221,568 KB
testcase_25 AC 515 ms
221,568 KB
testcase_26 AC 505 ms
221,568 KB
testcase_27 AC 521 ms
221,568 KB
testcase_28 AC 486 ms
221,568 KB
testcase_29 AC 516 ms
221,568 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 signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll P;
int X[4040],Y[4040];
int D[4040][4040];
ll L[4040][4040];
ll R[4040][4040];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>P;
	
	if(P==0) {
		ll ret=0;
		for(i=1;i<=N;i++) ret+=i*(i+1)/2;
		cout<<ret<<endl;
		return;
	}
	
	FOR(x,N) FOR(y,N) D[x][y]=101010;
	queue<pair<int,int>> Q;
	FOR(i,K) {
		cin>>x>>y;
		x--,y--;
		D[x][y]=0;
		Q.push({x,y});
	}
	
	while(Q.size()) {
		x=Q.front().first;
		y=Q.front().second;
		Q.pop();
		
		int dx[6]={-1,0,-1,1,0,1};
		int dy[6]={-1,-1,0,0,1,1};
		FOR(i,6) {
			int tx=x+dx[i];
			int ty=y+dy[i];
			if(tx<0 || tx>=N || ty<0 || ty>tx) continue;
			if(D[tx][ty]>D[x][y]+1) {
				D[tx][ty]=D[x][y]+1;
				Q.push({tx,ty});
			}
		}
	}
	
	for(x=N-1;x>=0;x--) {
		FOR(y,x+1) {
			L[x][y]=R[x][y]=D[x][y];
			L[x][y]+=L[x+1][y];
			R[x][y]+=R[x+1][y+1];
		}
	}
	
	ll ret=0;
	for(x=N-1;x>=0;x--) {
		ll S=0;
		for(int LL=0,RR=-1;LL<=x;LL++) {
			
			if(RR<=LL) RR=LL, S=0;
			while(RR<=x&&S+(R[x-(RR-LL)][LL]-R[x+1][RR+1])<P) {
				S+=(R[x-(RR-LL)][LL]-R[x+1][RR+1]);
				RR++;
			}
			ret+=x+1-RR;
			S-=(L[x-(RR-1-LL)][LL]-L[x+1][LL]);
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0