結果
問題 |
No.421 しろくろチョコレート
|
ユーザー |
![]() |
提出日時 | 2019-02-13 00:25:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,350 bytes |
コンパイル時間 | 547 ms |
コンパイル使用メモリ | 68,720 KB |
最終ジャッジ日時 | 2025-01-06 21:08:50 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:31:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%zu %zu", &N, &M); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%s", buf); | ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio> #include <vector> #include <string> #include <utility> #include <tuple> constexpr size_t di[] = {size_t(-1), 0, 1, 0}; constexpr size_t dj[] = {0, size_t(-1), 0, 1}; std::pair<int, int> dfs(std::vector<std::string>& s, size_t i, size_t j) { std::pair<int, int> wb; if (s[i][j] == '.') return {0, 0}; if (s[i][j] == 'w') ++wb.first; if (s[i][j] == 'b') ++wb.second; s[i][j] = '.'; for (int k = 0; k < 4; ++k) { size_t ni = i + di[k]; size_t nj = j + dj[k]; if (!(ni < s.size() && nj < s[0].length())) continue; if (s[ni][nj] == '.') continue; auto tmp = dfs(s, ni, nj); wb.first += tmp.first; wb.second += tmp.second; } return wb; } int main() { size_t N, M; scanf("%zu %zu", &N, &M); std::vector<std::string> S(N); for (auto& si: S) { char buf[64]; scanf("%s", buf); si = buf; } std::vector<std::pair<int, int>> wb; for (size_t i = 0; i < N; ++i) for (size_t j = 0; j < M; ++j) if (S[i][j] != '.') wb.push_back(dfs(S, i, j)); int res = 0; int w = 0; int b = 0; for (const auto& p: wb) { int wi, bi; std::tie(wi, bi) = p; if (wi < bi) { res += 100 * wi; b += bi-wi; } else { res += 100 * bi; w += wi-bi; } } if (w > b) std::swap(w, b); res += 10*w; res += b-w; printf("%d\n", res); }