結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | kmjp |
提出日時 | 2018-02-23 23:21:01 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,036 ms / 2,500 ms |
コード長 | 1,801 bytes |
コンパイル時間 | 1,576 ms |
コンパイル使用メモリ | 166,120 KB |
実行使用メモリ | 225,000 KB |
最終ジャッジ日時 | 2024-10-10 02:48:52 |
合計ジャッジ時間 | 20,871 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#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; }