結果

問題 No.640 76本のトロンボーン
ユーザー kotatsugame
提出日時 2020-03-25 03:28:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 69,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 17:24:02
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N;
string s[75],t[75];
int calc()
{
	int ret=0;
	bool ok[75][2]={};
	for(int i=0;i<N;i++)
	{
		bool out=false;
		for(int j=1;j<N-1;j++)
		{
			if(s[i][j]=='#')out=true;
		}
		if(!out)
		{
			if(s[i][0]!='#')ok[i][0]=true;
			if(s[i][N-1]!='#')ok[i][1]=true;
			if(ok[i][0]||ok[i][1])ret++;
		}
	}
	bool gt[4]={};
	for(int r=0;r<4;r++)
	{
		int now=0;
		bool row=true;
		for(int j=0;j<N-1;j++)
		{
			if(s[j+(r&2?1:0)][r&1?0:N-1]=='#')row=false;
		}
		gt[r]=row;
		if(row)now++;
		int id=r&2?0:N-1;
		if(ok[id][0]||ok[id][1])now++;
		for(int j=0;j<N-1;j++)
		{
			if(ok[j+(r&2?1:0)][r&1])now++;
		}
		ret=max(ret,now);
	}
	ret=max(ret,gt[0]+gt[1]+(ok[N-1][0]||ok[N-1][1]));
	ret=max(ret,gt[2]+gt[3]+(ok[0][0]||ok[0][1]));
	ret=max(ret,gt[0]+gt[3]+ok[0][0]+ok[N-1][1]);
	ret=max(ret,gt[1]+gt[2]+ok[0][1]+ok[N-1][0]);
	return ret;
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>s[i];
		t[i]=s[i];
	}
	int ans=calc();
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)s[i][j]=t[j][i];
	cout<<max(ans,calc())<<endl;
}
0