結果

問題 No.655 E869120 and Good Triangles
ユーザー Lepton_sLepton_s
提出日時 2018-02-24 00:04:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,158 ms / 2,500 ms
コード長 3,020 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 134,548 KB
実行使用メモリ 382,720 KB
最終ジャッジ日時 2023-08-11 01:09:35
合計ジャッジ時間 20,415 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,752 KB
testcase_01 AC 2 ms
5,468 KB
testcase_02 AC 2 ms
5,456 KB
testcase_03 AC 2 ms
5,452 KB
testcase_04 AC 2 ms
5,528 KB
testcase_05 AC 2 ms
5,748 KB
testcase_06 AC 2 ms
5,468 KB
testcase_07 AC 2 ms
5,588 KB
testcase_08 AC 2 ms
5,528 KB
testcase_09 AC 2 ms
5,536 KB
testcase_10 AC 1,109 ms
331,420 KB
testcase_11 AC 877 ms
350,512 KB
testcase_12 AC 994 ms
380,276 KB
testcase_13 AC 902 ms
382,132 KB
testcase_14 AC 922 ms
381,552 KB
testcase_15 AC 993 ms
382,248 KB
testcase_16 AC 1,158 ms
382,720 KB
testcase_17 AC 1,066 ms
382,576 KB
testcase_18 AC 1,061 ms
382,148 KB
testcase_19 AC 982 ms
382,420 KB
testcase_20 AC 1,091 ms
382,404 KB
testcase_21 AC 1,034 ms
382,576 KB
testcase_22 AC 862 ms
382,332 KB
testcase_23 AC 830 ms
382,556 KB
testcase_24 AC 378 ms
378,564 KB
testcase_25 AC 374 ms
378,712 KB
testcase_26 AC 382 ms
378,696 KB
testcase_27 AC 510 ms
378,572 KB
testcase_28 AC 370 ms
378,468 KB
testcase_29 AC 435 ms
378,548 KB
testcase_30 AC 2 ms
5,500 KB
testcase_31 AC 2 ms
5,592 KB
testcase_32 AC 2 ms
5,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 4010
int d[N][N];
int n, m;
ll S;
int dx[] = {-1,-1,0,1,1,0}, dy[] = {0,-1,-1,0,1,1};
ll w1[N][N], w2[N][N];
int memo[N][N];

ll f(ll x, ll y, ll z){
	ll r = w1[y][n-x+2]-w1[y+z][n-x+2-z];
	r -= w2[n+1][y+z]-w2[n+1][y]-w2[x+z][y+z]+w2[x+z][y];
	return r;
}

int main(){
	INIT;
	//scanf("%d%d%lld", &n, &m, &S);
	cin>>n>>m>>S;
	rep1(i, n) fill(d[i]+1, d[i]+i+1, INF);
	queue<P> q;
	rep(i, m){
		ll x, y;
		cin>>x>>y;
		d[x][y] = 0;
		q.push(P(x, y));
	}
	while(!q.empty()){
		P p = q.front(); q.pop();
		int x = p.fst, y = p.snd;
		rep(i, 6){
			int x2 = x+dx[i], y2= y+dy[i];
			if(x2<1||y2<1||x2>n||y2>x2||d[x2][y2]<INF) continue;
			d[x2][y2] = d[x][y]+1;
			q.push(P(x2, y2));
		}
	}
	rep1(i, n) rep1(j, n+1) w2[i+1][j+1] = w2[i][j+1]+w2[i+1][j]-w2[i][j]+d[i][j];
	rep1(i, n){
		w1[1][i+1] = w1[1][i];
		rep(j, i) w1[1][i+1] += d[n-j][j+1];
	}
	rep1(i, n) rep1(j, n-i+1) w1[i+1][j] = w1[i][j+1]-(w2[n+1][i+1]-w2[n-j+1][i+1]-w2[n+1][i]+w2[n-j+1][i]);
	ll res = 0;
	rep1(i, n) rep1(j, i){
		int lb = max(0, max(memo[i-1][j-1], memo[i-1][j])-2), ub = n-i+2;
		bool first = true;
		while(ub-lb>1){
			int md = (lb+ub+1)/2;
			if(first){
				md = (lb*3+ub+1)/4;
				if(md==lb) md++;
				first = false;
			}
			(f(i, j, md)>=S?ub:lb)=md;
		}
		memo[i][j] = ub;
		res += n-i+2-ub;
	}
	//printf("%lld\n", res);
	cout<<res<<endl;
	return 0;
}
0