結果

問題 No.640 76本のトロンボーン
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-27 00:20:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,584 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 79,660 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:00:14
合計ジャッジ時間 1,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0