結果

問題 No.348 カゴメカゴメ
ユーザー parukiparuki
提出日時 2016-06-17 17:56:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,984 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 180,820 KB
実行使用メモリ 18,172 KB
最終ジャッジ日時 2024-04-17 23:09:42
合計ジャッジ時間 4,952 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
9,856 KB
testcase_01 WA -
testcase_02 AC 75 ms
18,172 KB
testcase_03 AC 39 ms
12,444 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 5 ms
8,548 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,948 KB
testcase_15 AC 40 ms
8,640 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 3 ms
6,940 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 6 ms
6,940 KB
testcase_34 AC 6 ms
6,940 KB
testcase_35 AC 7 ms
6,944 KB
testcase_36 AC 6 ms
6,944 KB
testcase_37 AC 6 ms
6,940 KB
testcase_38 AC 6 ms
6,940 KB
testcase_39 AC 5 ms
6,940 KB
testcase_40 AC 5 ms
6,944 KB
testcase_41 AC 7 ms
6,944 KB
testcase_42 AC 6 ms
6,940 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 3 ms
6,944 KB
testcase_48 AC 3 ms
6,940 KB
testcase_49 AC 3 ms
6,940 KB
testcase_50 AC 3 ms
6,944 KB
testcase_51 WA -
testcase_52 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

struct R{
    vector<pii> ps;
    vi ch;
};

const int MAX = 1010;
int H, W, vis[MAX][MAX];
char g[MAX][MAX];
vector<R> rn;

void mkR(int sy, int sx){
    R r;
    queue<pair<int, int>> Q;
    Q.push(mp(sy, sx));
    while(sz(Q)){
        int y, x;
        tie(y, x) = Q.front();
        Q.pop();
        if(vis[y][x]++)continue;
        r.ps.emplace_back(y, x);
        rep(i, 8){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny<0||nx<0||ny>=H||nx>=W||vis[ny][nx]||g[ny][nx]=='.')continue;
            Q.push(mp(ny, nx));
        }
    }
    rn.push_back(r);
}

vi bfs(int sy, int sx){
    vi res;
    queue<pair<int, int>> Q;
    Q.push(mp(sy, sx));
    while(sz(Q)){
        int y, x;
        tie(y, x) = Q.front();
        Q.pop();
        if(vis[y][x]++)continue;
        if(g[y][x] == 'x'){
            res.push_back(sz(rn));
            vis[y][x] = 0;
            mkR(y, x);
            continue;
        }
        rep(i, 4){
            int ny = y + DY[i];
            int nx = x + DX[i];
            if(ny<0||nx<0||ny>=H||nx>=W||vis[ny][nx])continue;
            Q.push(mp(ny, nx));
        }
    }
    return res;
}

void init(){
    cin >> H >> W;
    MEM(g, '.');
    rep(y, H){
        scanf("%s", g[y+1] + 1);
        g[y+1][W + 1] = '.';
    }
    H += 2;
    W += 2;
    rn.push_back(R());
    for(int p = 0; p < sz(rn); ++p){
        int sy = -1, sx = -1;
        if(p == 0){
            sy = sx = 0;
        } else{
            each(q, rn[p].ps){
                int y, x;
                tie(y, x) = q;
                rep(i, 4){
                    int ny = y + DY[i];
                    int nx = x + DX[i];
                    if(ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
                    if(g[ny][nx] == '.' && !vis[ny][nx]){
                        sy = ny;
                        sx = nx;
                        break;
                    }
                }
                if(sy != -1)break;
            }
        }
        if(sy != -1)rn[p].ch = bfs(sy, sx);
    }
}

int solve(int id, int use){
    int res = use*sz(rn[id].ps);
    each(ch, rn[id].ch)
        res += solve(ch, 1 - use);
    return res;
}

int main(){
    init();
    int ans = 0;
    each(id, rn[0].ch)
        ans += max(solve(id, 0), solve(id, 1));
    cout << ans << endl;
}
0