結果

問題 No.421 しろくろチョコレート
ユーザー h_noson
提出日時 2016-09-16 19:47:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,540 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 82,772 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 08:03:37
合計ジャッジ時間 2,945 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

string s[50];
int w = 0, b = 0, ans = 0;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int n, m;
bool used[50][50];

char dfs(int y, int x) {
    used[y][x] = true;
    int i;
    REP (i,4) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (ny < 0 || ny >= n || nx < 0 || nx >= m || used[ny][nx] || s[ny][nx] == '.') continue;
        char res = dfs(ny,nx);
        if (res != '.') {
            if (s[y][x] != '.') {
                ans += 100;
                s[y][x] = '.';
            }
            else if (res == 'w') w++;
            else b++;
        }
    }
    char ret = s[y][x];
    s[y][x] = '.';
    return ret;
}

int main(void) {
    int i, j;
    cin >> n >> m;
    REP (i,n) cin >> s[i];
    REP (i,n) REP (j,m) if (s[i][j] != '.') {
        char res = dfs(i,j);
        if (res == 'w')
            w++;
        else if (res == 'b')
            b++;
    }
    int mn = min(w,b);
    ans += mn * 10 + w + b - 2 * mn;
    cout << ans << endl;
    return 0;
}
0