結果
問題 | No.2837 Flip Triomino |
ユーザー |
![]() |
提出日時 | 2024-08-09 21:59:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 3,666 bytes |
コンパイル時間 | 2,761 ms |
コンパイル使用メモリ | 258,064 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-08-09 21:59:09 |
合計ジャッジ時間 | 3,826 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#if __INCLUDE_LEVEL__ == 0#include __BASE_FILE__using Mint = atcoder::modint998244353;void Solve() {int h, w;IN(h, w);vector<string> s(h);IN(s);int mask = 0;array<int, 3> c{};for (int i : Rep(h)) {for (int j : Rep(w)) {int r = (i + j) % 3;if (s[i][j] == 'W') {} else if (s[i][j] == 'B') {mask ^= 1 << r;} else {++c[r];}}}Mint ans = 0;for (int p : Rep(2)) {Mint cur = 1;for (int r : Rep(3)) {if ((mask >> r & 1) == p) {cur *= c[r] == 0 ? 1 : Mint(2).pow(c[r] - 1);} else {cur *= c[r] == 0 ? 0 : Mint(2).pow(c[r] - 1);}}ans += cur;}OUT(ans);}int main() {ios::sync_with_stdio(false);cin.tie(nullptr);Solve();}#elif __INCLUDE_LEVEL__ == 1#include <bits/stdc++.h>#include <atcoder/modint>template <class T> concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;template <class T> concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;namespace std {istream& operator>>(istream& is, Range auto&& r) {for (auto&& e : r) {is >> e;}return is;}istream& operator>>(istream& is, Tuple auto&& t) {return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);}ostream& operator<<(ostream& os, Range auto&& r) {for (string_view sep = ""; auto&& e : r) {os << exchange(sep, " ") << e;}return os;}ostream& operator<<(ostream& os, Tuple auto&& t) {return apply([&](auto&... xs) -> ostream& {[[maybe_unused]] string_view sep = "";((os << exchange(sep, " ") << xs), ...);return os; }, t);}template <class T, atcoder::internal::is_modint_t<T>* = nullptr>istream& operator>>(istream& is, T& x) {int v;is >> v;x = T::raw(v);return is;}template <class T, atcoder::internal::is_modint_t<T>* = nullptr>ostream& operator<<(ostream& os, const T& x) {return os << x.val();}} // namespace std#define DEF_INC_OR_DEC(op) \auto& operator op(Tuple auto&&); \auto& operator op(Range auto&& r) { \for (auto&& e : r) { \op e; \} \return r; \} \auto& operator op(Tuple auto&& t) { \std::apply([](auto&... xs) { (op xs, ...); }, t); \return t; \}DEF_INC_OR_DEC(++)DEF_INC_OR_DEC(--)#undef DEF_INC_OR_DEC#define IN(...) cin >> forward_as_tuple(__VA_ARGS__)#define OUT(...) cout << forward_as_tuple(__VA_ARGS__) << '\n'using namespace std;using views::filter, views::transform, views::take, views::drop;constexpr auto Rev = views::reverse;constexpr auto Rep(int l, int r) { return views::iota(min(l, r), r); }constexpr auto Rep(int n) { return Rep(0, n); }constexpr auto Rep1(int l, int r) { return Rep(l, r + 1); }constexpr auto Rep1(int n) { return Rep(1, n + 1); }constexpr auto DivFloor(auto x, auto y) { return x / y - ((x ^ y) < 0 && x % y != 0); }constexpr auto DivCeil(auto x, auto y) { return x / y + (0 <= (x ^ y) && x % y != 0); }constexpr auto Floor(auto x, auto y) { return DivFloor(x, y) * y; }constexpr auto Floor(auto x, auto y, auto z) { return Floor(x - z, y) + z; }constexpr auto Ceil(auto x, auto y) { return DivCeil(x, y) * y; }constexpr auto Ceil(auto x, auto y, auto z) { return Ceil(x - z, y) + z; }constexpr auto Mod(auto x, auto y) { return x - Floor(x, y); }template <class T, class U = T> bool SetMin(T& x, U&& y) { return y < x && (x = forward<U>(y), true); }template <class T, class U = T> bool SetMax(T& x, U&& y) { return x < y && (x = forward<U>(y), true); }constexpr int INF = INT_MAX / 2;constexpr int64_t INF64 = INT64_MAX / 2;#endif // __INCLUDE_LEVEL__ == 1