結果

問題 No.348 カゴメカゴメ
ユーザー latte0119latte0119
提出日時 2016-02-26 23:17:59
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,278 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 173,160 KB
実行使用メモリ 41,076 KB
最終ジャッジ日時 2023-10-24 06:18:35
合計ジャッジ時間 5,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
36,324 KB
testcase_01 AC 12 ms
35,116 KB
testcase_02 AC 107 ms
41,076 KB
testcase_03 AC 100 ms
36,460 KB
testcase_04 AC 13 ms
35,024 KB
testcase_05 AC 12 ms
36,104 KB
testcase_06 AC 11 ms
35,040 KB
testcase_07 AC 11 ms
35,032 KB
testcase_08 AC 11 ms
35,024 KB
testcase_09 AC 11 ms
35,052 KB
testcase_10 AC 11 ms
35,044 KB
testcase_11 AC 11 ms
35,044 KB
testcase_12 AC 12 ms
35,252 KB
testcase_13 AC 11 ms
35,164 KB
testcase_14 AC 11 ms
35,108 KB
testcase_15 AC 18 ms
36,108 KB
testcase_16 AC 11 ms
35,032 KB
testcase_17 AC 11 ms
35,032 KB
testcase_18 AC 10 ms
35,032 KB
testcase_19 AC 12 ms
35,032 KB
testcase_20 AC 12 ms
35,064 KB
testcase_21 AC 11 ms
35,072 KB
testcase_22 AC 10 ms
35,032 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 18 ms
35,356 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 16 ms
35,356 KB
testcase_37 AC 15 ms
35,352 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 12 ms
35,216 KB
testcase_44 AC 12 ms
35,216 KB
testcase_45 AC 12 ms
35,216 KB
testcase_46 AC 11 ms
35,232 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 12 ms
35,216 KB
testcase_50 AC 12 ms
35,232 KB
testcase_51 AC 12 ms
35,216 KB
testcase_52 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |     scanf("%d%d",&H,&W);
      |     ~~~~~^~~~~~~~~~~~~~
main.cpp:65:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |     rep(i,H)scanf("%s",fld[i]);
      |             ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

//Sinjirukimoti is daiji
//Usokaihou is here

int dx[]={-1,0,1,-1,1,-1,0,1};
int dy[]={-1,-1,-1,0,0,1,1,1};

int H,W;
char fld[1111][1111];

vint G[1000000];

int N;
int sz[1000000];
int C[1111][1111];
bool used[1111][1111];
bool isroot[1000000];

void dfs(int y,int x){
    used[y][x]=true;
    sz[N]++;
    C[y][x]=N;

    rep(i,8){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0||ny>=H||nx<0||nx>=W||used[ny][nx]||fld[ny][nx]=='.')continue;
        dfs(ny,nx);
    }
}

int dp[1000000][2];

void solve(int v,int p){
    dp[v][0]=0;dp[v][1]=sz[v];
    rep(i,G[v].size()){
        int to=G[v][i];
        if(to==p)continue;
        solve(to,v);
        dp[v][0]+=max(dp[to][0],dp[to][1]);
        dp[v][1]+=dp[to][0];
    }
}

signed main(){
    scanf("%d%d",&H,&W);
    rep(i,H)scanf("%s",fld[i]);

    memset(C,-1,sizeof(C));
    rep(i,H)rep(j,W)if(!used[i][j]&&fld[i][j]=='x'){
        dfs(i,j);
        N++;
    }
    fill_n(isroot,N,1);
    rep(i,H){
        stack<int>S;
        map<int,int>M,MM;
        rep(j,W)if(C[i][j]!=-1)M[C[i][j]]=j;
        for(int j=W-1;j>=0;j--)if(C[i][j]!=-1)MM[C[i][j]]=j;

        rep(j,W){
            if(C[i][j]==-1)continue;
            if(MM[C[i][j]]==j){
                if(isroot[C[i][j]]&&S.size()){
                    G[S.top()].pb(C[i][j]);
                    G[C[i][j]].pb(S.top());
                    isroot[C[i][j]]=0;
                }
                S.push(C[i][j]);
            }
            if(M[C[i][j]]==j){
                assert(S.size());
                S.pop();
            }
        }
    }

    int ans=0;
    rep(i,N)if(isroot[i]){
        solve(i,-1);
        ans+=max(dp[i][0],dp[i][1]);
    }
    printf("%d\n",ans);
    return 0;
}
0