結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | Lepton_s |
提出日時 | 2018-02-24 00:04:16 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,678 ms / 2,500 ms |
コード長 | 3,020 bytes |
コンパイル時間 | 7,078 ms |
コンパイル使用メモリ | 165,568 KB |
最終ジャッジ日時 | 2025-01-05 08:45:45 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#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; }