結果

問題 No.640 76本のトロンボーン
ユーザー WA_TLEWA_TLE
提出日時 2017-11-21 16:52:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,656 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 121,408 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:59:23
合計ジャッジ時間 1,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
#include<map>
#include<bitset>
#include<array>
#include<cmath>
#include<functional>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const llint big=1e15+100000;
const int mod=1e9+7;
const lldo eps=1e-7;
const long double pai=3.141592653589793238462643383279502884197;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
#define dme(in) cout<<in<<endl;return 0
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	int n,i,j,ans=0;cin>>n;
	vector<string>ko(n);
	for(i=0;i<n;i++){cin>>ko[i];}
	//n+1本判定
	//よことたてのどちらかは1本以内
	//その場所を全探索
	//よこたくさん
	int gen=0;
	{
		string hid;
		string mig;
	for(i=0;i<n;i++){
		int che=1;
		for(j=1;j<n-1;j++){if(ko[i][j]=='#'){che=0;}}
		if(che==1){
			if(ko[i][0]=='.'&&ko[i][n-1]=='.'){hid.pub('.');mig.pub('.');gen++;}
			else if(ko[i][0]=='.'||ko[i][n-1]=='.'){hid.pub('#');mig.pub('#');gen++;}
			else{hid.pub('#');mig.pub('#');}
		}else{hid.pub(ko[i][0]);mig.pub(ko[i][n-1]);}
	}
		int hce=1;
		for(j=1;j<n-1;j++){if(hid[j]=='#'){hce=0;}}
		if(hid[0]=='#'&&hid[n-1]=='#'){hce=0;}
		int mce=1;
		for(j=1;j<n-1;j++){if(mig[j]=='#'){mce=0;}}
		if(mig[0]=='#'&&mig[n-1]=='#'){mce=0;}
		gen+=max(hce,mce);
	}
	ans=gen;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			swap(ko[i][j],ko[j][i]);
		}
	}
	gen=0;
	{
		string hid;
		string mig;
	for(i=0;i<n;i++){
		int che=1;
		for(j=1;j<n-1;j++){if(ko[i][j]=='#'){che=0;}}
		if(che==1){
			if(ko[i][0]=='.'&&ko[i][n-1]=='.'){hid.pub('.');mig.pub('.');gen++;}
			else if(ko[i][0]=='.'||ko[i][n-1]=='.'){hid.pub('#');mig.pub('#');gen++;}
			else{hid.pub('#');mig.pub('#');}
		}else{hid.pub(ko[i][0]);mig.pub(ko[i][n-1]);}
	}
		int hce=1;
		for(j=1;j<n-1;j++){if(hid[j]=='#'){hce=0;}}
		if(hid[0]=='#'&&hid[n-1]=='#'){hce=0;}
		int mce=1;
		for(j=1;j<n-1;j++){if(mig[j]=='#'){mce=0;}}
		if(mig[0]=='#'&&mig[n-1]=='#'){mce=0;}
		gen+=max(hce,mce);
	}
	maxeq(ans,gen);
	
	//----|
	//|###|
	//|###|
	//|###|
	//|----
	int sai=1;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i==0||i==n-1||j==0||j==n-1){
				if(ko[i][j]=='#'){sai=0;}
			}
		}
	}
	if(sai==1){maxeq(ans,4);}
	cout<<ans<<endl;
	return 0;
};
0