結果
問題 | No.640 76本のトロンボーン |
ユーザー |
![]() |
提出日時 | 2018-01-27 00:20:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,584 bytes |
コンパイル時間 | 683 ms |
コンパイル使用メモリ | 78,912 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 17:21:32 |
合計ジャッジ時間 | 1,253 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#include<algorithm> #include<cassert> #include<iostream> #include<vector> using namespace std; typedef long long lint; typedef vector<int>vi; typedef pair<int,int>pii; #define rep(i,n)for(int i=0;i<(int)(n);++i) vector<string> rotate(const vector<string> &s){ int n=s.size(); vector<string>r(n,string(n,'*')); rep(i,n){ rep(j,n){ r[i][j]=s[j][n-1-i]; } } return r; } void flip(vector<string> &s){ int n=s.size(); rep(i,n){ rep(j,n/2){ swap(s[i][j],s[i][n-1-j]); } } } int f(const vector<string> &s){ int n=s.size(); vector<vi>t(n,vi(2,0)); int ma=0; rep(i,n){ bool ok=true; for(int j=1;j<n-1;++j)if(s[i][j]=='#')ok=false; if(!ok)continue; t[i][0]=s[i][0]=='.'?1:0; t[i][1]=s[i][n-1]=='.'?1:0; } rep(i,n)ma+=t[i][0]||t[i][1]?1:0; //check bool ok=true; rep(k,n-1)if(s[k][0]=='#')ok=false; if(ok){ int tmp=1; rep(k,n-1)tmp+=t[k][1]; tmp+=t[n-1][0]||t[n-1][1]?1:0; ma=max(ma,tmp); bool ok2=true; rep(j,n-1)if(s[j+1][n-1]=='#')ok2=false; if(ok2&&t[0][1]&&t[n-1][0])ma=max(ma,4); } if(0){ rep(i,n)cerr<<s[i]<<endl; rep(i,n)cerr<<t[i][0]<<" "<<t[i][1]<<endl; cerr<<"ma="<<ma<<endl; cerr<<endl; } return ma; } int main(){ int n; cin>>n; assert(n>=3&&n<=75); vector<string>s(n); rep(i,n)cin>>s[i]; rep(i,n)assert((int)s.size()==n); rep(i,n){ rep(j,n){ assert(s[i][j]=='.'||s[i][j]=='#'); } } int ma=0; rep(qwerty,4){ rep(uiop,2){ ma=max(ma,f(s)); flip(s); } s=rotate(s); } cout<<ma<<endl; }