結果
| 問題 | 
                            No.640 76本のトロンボーン
                             | 
                    
| コンテスト | |
| ユーザー | 
                             WA_TLE
                         | 
                    
| 提出日時 | 2017-11-21 16:52:41 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 2,656 bytes | 
| コンパイル時間 | 1,138 ms | 
| コンパイル使用メモリ | 119,936 KB | 
| 最終ジャッジ日時 | 2025-01-05 04:16:54 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 15 | 
ソースコード
#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;
};
            
            
            
        
            
WA_TLE