結果

問題 No.421 しろくろチョコレート
ユーザー face4face4
提出日時 2018-11-29 16:00:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,538 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 75,436 KB
実行使用メモリ 4,572 KB
最終ジャッジ日時 2023-09-09 05:54:12
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 考察が何か足らない気がする、
// 絶対コーナーケースがある
#include<iostream>
#include<queue>
using namespace std;

#define inRange(x,a,b) (a <= x && x < b)

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

int main(){
    int h, ww;
    cin >> h >> ww;

    char mat[h][ww];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < ww; j++){
            cin >> mat[i][j];
        }
    }

    int ans = 0, resw = 0, resb = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < ww; j++){
            if(mat[i][j] == '.')    continue;
            int w = 0, b = 0;
            queue<pair<int,int>> q;
            q.push({i,j});
            while(!q.empty()){
                pair<int,int> p = q.front();    q.pop();
                if(mat[p.first][p.second] == '.')   continue;
                if(mat[p.first][p.second] == 'w')   w++;
                else                                b++;
                mat[p.first][p.second] = '.';
                
                for(int k = 0; k < 4; k++){
                    int ni = p.first + dx[k], nj = p.second + dy[k];
                    if(inRange(ni,0,h) && inRange(nj,0,ww) && mat[ni][nj] != '.')    q.push({ni,nj});
                }
            }
            
            int consec = min(w,b);
            ans += 100 * consec;
            resw += w-consec, resb += b-consec;
        }
    }

    int apart = min(resb, resw);
    ans += 10 * apart;
    ans += resb-apart + resw-apart;

    cout << ans << endl;

    return 0;
}
0