結果

問題 No.2456 Stamp Art
ユーザー 👑 kmjpkmjp
提出日時 2023-09-01 23:03:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 753 ms / 5,000 ms
コード長 1,568 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 201,524 KB
実行使用メモリ 133,704 KB
最終ジャッジ日時 2023-09-02 11:19:39
合計ジャッジ時間 16,967 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
129,408 KB
testcase_01 AC 117 ms
129,500 KB
testcase_02 AC 215 ms
129,440 KB
testcase_03 AC 606 ms
133,704 KB
testcase_04 AC 56 ms
68,076 KB
testcase_05 AC 166 ms
129,556 KB
testcase_06 AC 731 ms
133,536 KB
testcase_07 AC 696 ms
133,552 KB
testcase_08 AC 689 ms
133,488 KB
testcase_09 AC 725 ms
133,452 KB
testcase_10 AC 737 ms
133,520 KB
testcase_11 AC 712 ms
133,584 KB
testcase_12 AC 706 ms
133,544 KB
testcase_13 AC 753 ms
133,524 KB
testcase_14 AC 722 ms
133,576 KB
testcase_15 AC 601 ms
133,568 KB
testcase_16 AC 638 ms
131,640 KB
testcase_17 AC 166 ms
129,424 KB
testcase_18 AC 56 ms
68,060 KB
testcase_19 AC 550 ms
132,032 KB
testcase_20 AC 728 ms
133,536 KB
testcase_21 AC 712 ms
133,116 KB
testcase_22 AC 716 ms
133,564 KB
testcase_23 AC 432 ms
129,736 KB
testcase_24 AC 535 ms
129,828 KB
testcase_25 AC 168 ms
129,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#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 FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W;
string S[2020];
int D[4020][4020];
int E[4020][4020];

int ok(int v) {
	if(v>min(H,W)) return 0;
	
	ZERO(E);
	int y,x;
	for(y=v-1;y<H;y++) for(x=v-1;x<W;x++) {
		int num=D[y+1][x+1]-D[y+1-v][x+1]-D[y+1][x+1-v]+D[y+1-v][x+1-v];
		if(num==v*v) E[y+1][x+1]++;
	}
	FOR(y,4010) FOR(x,4010) if(x&&y) E[y][x]+=E[y-1][x]+E[y][x-1]-E[y-1][x-1];
	FOR(y,H) FOR(x,W) if(S[y][x]=='#') {
		if(E[y+v][x+v]-E[y][x+v]-E[y+v][x]+E[y][x]==0) return 0;
	}
	return 1;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			D[y+1][x+1]=(S[y][x]=='#');
		}
	}
	
	FOR(y,4010) FOR(x,4010) if(x&&y) D[y][x]+=D[y-1][x]+D[y][x-1]-D[y-1][x-1];
	
	
	int cur=1;
	for(i=10;i>=0;i--) {
		if(ok(cur+(1<<i))) cur+=1<<i;
	}
	cout<<cur<<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