結果

問題 No.348 カゴメカゴメ
ユーザー kzyKTkzyKT
提出日時 2016-02-26 23:39:22
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,612 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 164,512 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 10:12:44
合計ジャッジ時間 12,200 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1 ms
4,348 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 70 ms
4,348 KB
testcase_05 RE -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 2 ms
4,348 KB
testcase_15 RE -
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 TLE -
testcase_48 AC 420 ms
4,348 KB
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 AC 423 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1};
typedef pair<int,int> P;

int n,m;
string s[111];
int c[111][111],u[111][111],cnt,d[111],M;
vector<int> v[111];

void dfs(int nx,int ny,int f,int z) {
  if(f&&s[nx][ny]!='x') return;
  if(f) u[nx][ny]=1,cnt++;
  c[nx][ny]=z;
  if(f) {
    rep(i,8) {
      int x=nx+dx[i],y=ny+dy[i];
      if(check(n,m,x,y)&&!u[x][y]) dfs(x,y,f,z);
    }
  } else {
    for(int i=-1; i<2; i++) {
      for(int j=-1; j<2; j++) {
        if(i&&j) continue;
        int x=nx+i,y=ny+j;
        if(!check(n,m,x,y)) M=0;
        if(u[x][y]) M=min(M,c[x][y]);
        if(check(n,m,x,y)&&!u[x][y]&&c[x][y]!=z) dfs(x,y,f,z);
      }
    }
  }
}

P solve(int x) {
  P p=P(0,0);
  rep(i,v[x].size()) {
    P q=solve(v[x][i]);
    p.F+=q.S;
    p.S+=max(q.F,q.S);
  }
  p.F+=d[x];
  return p;
}

void Main() {
  cin >> n >> m;
  rep(i,n) cin >> s[i];
  int k=1;
  rep(i,n) {
    rep(j,m) {
      if(s[i][j]=='x'&&!u[i][j]) {
        int z=c[i][j];
        cnt=0;
        dfs(i,j,1,k);
        d[k]=cnt;
        k++;
      }
    }
  }
  rep(i,n) {
    rep(j,m) {
      if(s[i][j]!='x'&&c[i][j]==0) {
        M=MAX;
        dfs(i,j,0,-1);
        dfs(i,j,0,M);
      }
    }
  }
  int e[111];
  fill(e,e+111,MAX);
  rep(i,n) {
    rep(j,m) {
      if(!c[i][j]) continue;
      rep(k,8) {
        int x=i+dx[k],y=j+dy[k];
        if(!check(n,m,x,y)) e[c[i][j]]=0;
        else e[c[i][j]]=min(e[c[i][j]],c[x][y]);
      }
    }
  }
  rep(i,111) {
    if(e[i]!=MAX) v[e[i]].pb(i);
  }
  P p=solve(0);
  pr(max(p.F,p.S));
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
0