結果
問題 |
No.421 しろくろチョコレート
|
ユーザー |
|
提出日時 | 2016-09-09 23:40:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,107 bytes |
コンパイル時間 | 1,899 ms |
コンパイル使用メモリ | 157,928 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 18:43:34 |
合計ジャッジ時間 | 3,060 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d %d", &N, &M); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:32:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | char tmp[51]; scanf("%s", tmp); | ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; // #define NDEBUG #include <assert.h> #define MAX 50 int N, M; char S[MAX][MAX]; int f; int b, w, bt, wt; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; void dfs(int x, int y) { if (x < 0 || y < 0 || x >= N || y >= M || S[x][y] == '.') return; char c = S[x][y]; S[x][y] = '.'; if (c == 'b') bt++; if (c == 'w') wt++; for (int i = 0; i < 4; i++) { dfs(x + dx[i], y + dy[i]); } } int main() { f = b = w = 0; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) { char tmp[51]; scanf("%s", tmp); for (int j = 0; j < M; j++) { S[i][j] = tmp[j]; } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (S[i][j] == '.') { continue; } bt = wt = 0; dfs(i, j); f += min(bt, wt) * 100; if (bt > wt) b += bt - wt; if (bt < wt) w += wt - bt; } } if (b < w) swap(b, w); f += 10 * w; f += b - w; printf("%d", f); return 0; }