結果

問題 No.348 カゴメカゴメ
ユーザー rickythetarickytheta
提出日時 2016-02-26 23:29:56
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,897 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 166,520 KB
実行使用メモリ 75,104 KB
最終ジャッジ日時 2023-10-24 09:45:19
合計ジャッジ時間 7,417 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
32,304 KB
testcase_01 AC 3 ms
8,268 KB
testcase_02 AC 90 ms
44,332 KB
testcase_03 AC 84 ms
16,780 KB
testcase_04 AC 3 ms
8,444 KB
testcase_05 AC 3 ms
12,536 KB
testcase_06 AC 3 ms
8,256 KB
testcase_07 AC 2 ms
8,256 KB
testcase_08 AC 2 ms
8,256 KB
testcase_09 AC 2 ms
8,264 KB
testcase_10 AC 3 ms
8,264 KB
testcase_11 AC 3 ms
8,260 KB
testcase_12 AC 5 ms
9,440 KB
testcase_13 AC 3 ms
8,388 KB
testcase_14 AC 2 ms
8,276 KB
testcase_15 AC 106 ms
75,104 KB
testcase_16 AC 3 ms
8,256 KB
testcase_17 AC 2 ms
8,256 KB
testcase_18 AC 3 ms
8,256 KB
testcase_19 AC 3 ms
8,256 KB
testcase_20 AC 2 ms
8,272 KB
testcase_21 AC 2 ms
8,260 KB
testcase_22 AC 3 ms
8,256 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 9 ms
9,764 KB
testcase_34 AC 8 ms
9,604 KB
testcase_35 AC 9 ms
9,520 KB
testcase_36 AC 9 ms
9,460 KB
testcase_37 AC 9 ms
9,748 KB
testcase_38 AC 9 ms
9,320 KB
testcase_39 AC 8 ms
9,352 KB
testcase_40 AC 8 ms
9,500 KB
testcase_41 AC 9 ms
9,460 KB
testcase_42 AC 8 ms
9,660 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 3 ms
8,440 KB
testcase_48 AC 3 ms
8,376 KB
testcase_49 AC 3 ms
8,348 KB
testcase_50 AC 3 ms
8,464 KB
testcase_51 AC 3 ms
8,344 KB
testcase_52 AC 3 ms
8,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int n,m;
int mp[1252][1252];
int po[1252][1252];

int vx[8] = {1,0,-1,0,1,1,-1,-1};
int vy[8] = {0,1,0,-1,1,-1,-1,1};

int dfs(int a,int b,int id){
  if(a<0 || a>=n || b<0 || b>=m)return 0;
  if(mp[a][b] >= 0)return 0;
  mp[a][b] = id;
  int res = 1;
  REP(i,8){
    res += dfs(a+vx[i],b+vy[i],id);
  }
  return res;
}

void dfs2(int a,int b,int par){
  if(a<0 || a>=n || b<0 || b>=m)return;
  if(mp[a][b] == -1)return;
  if(mp[a][b] > 0){
    po[a][b] = par;
    if(mp[a][b]!=par)return;
  }
  mp[a][b] = -1;
  REP(i,4) dfs2(a+vx[i],b+vy[i],par);
}

struct node{
  int val;
  vector<node*> ch;
  node(int v):val(v){
    ch = vector<node*>();
  }
  void addch(node* n){
    ch.push_back(n);
  }
};

node* yey[125252];
// first: 直前を使った状態を含むmax
// second: 直前を使ってない状態のmax
pii dfs3(node* a){
  pii ret;
  int cnt = a->ch.size();
  pii sum;
  REP(i,cnt){
    pii rec = dfs3(a->ch[i]);
    sum.first += rec.first;
    sum.second += rec.second;
  }
  ret.first = a->val + sum.second;
  ret.second = max(sum.first, sum.second);
  return ret;
}

int main(){
  cin>>n>>m;
  n+=2;
  m+=2;
  REP(i,n){
    string s;
    if(i==0 || i==n-1){
      s = string(m,'.');
    }else{
      cin>>s;
      s = '.' + s + '.';
    }
    REP(j,m){
      mp[i][j] = (s[j]=='x'?-1:0);
    }
  }
  // grouping
  int wawa[125252];
  int iter = 1;
  REP(i,n)REP(j,m){
    if(mp[i][j]>=0)continue;
    wawa[iter] = dfs(i,j,iter);
    iter++;
  }
  iter--;
  // iter個の輪っか
  // 被覆しながら木構造の形成
  int left=0, top=0, right=n-1, bottom=m-1;
  int root = 125222;
  yey[root] = new node(0);
  dfs2(0,0,root);
  while(true){
    bool flag = false;
    int nl,nt,nr,nb;
    nl=right;
    nt=bottom;
    nr=left;
    nb=top;
    FOR(i,left,right+1)FOR(j,top,bottom+1){
      if(mp[i][j]<=0)continue;
      nl=min<int>(nl,i);
      nr=max<int>(nr,i);
      nt=min<int>(nt,j);
      nb=min<int>(nb,j);
      int id = mp[i][j];
      yey[id] = new node(wawa[id]);
      yey[po[i][j]]->addch(yey[id]);
      dfs2(i,j,id);
      flag = true;
    }
    if(!flag)break;
    left=nl;
    right=nr;
    top=nt;
    bottom=nb;
  }
  // 終わった~~~~~
  int res = 0;
  REP(i,(yey[root]->ch).size()){
    node* to = (yey[root]->ch)[i];
    pii x = dfs3(to);
    res += max(x.first,x.second);
  }
  cout<<res<<endl;
  return 0;
}
0