結果
問題 | No.226 0-1パズル |
ユーザー |
|
提出日時 | 2023-10-03 19:56:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,555 bytes |
コンパイル時間 | 3,684 ms |
コンパイル使用メモリ | 255,840 KB |
最終ジャッジ日時 | 2025-02-17 04:08:42 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace atcoder;#ifdef LOCAL#include <debug.h>#define dbg(...) debug::dbg(#__VA_ARGS__, __VA_ARGS__)#else#define dbg(...) void(0)#endifusing namespace std;// #define int long long#define rep(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i < i##_end__; i++)#define rep_r(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i >= i##_end__; i--)#define fore(i, a) for(auto& i: a)#define all(x) std::begin(x), std::end(x)using ll = long long; // __int128;using ull = unsigned long long;template<class C> int siz(const C& c) { return static_cast<int>(c.size()); }template<class T, size_t N> constexpr int siz(const T (&)[N]) { return static_cast<int>(N); }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }template<class T> constexpr T pow2(T x){ return x * x; }template<class T, class S> constexpr T divceil(T x, S div) { return (x % div == 0) ? x / div : (x >= 0) ? (x / div) + 1 : -((-x) / div); }template<class T, class S> constexpr T divfloor(T x, S div){ return (x % div == 0) ? x / div : (x >= 0) ? (x / div) : -((-x) / div) - 1; }constexpr long long INF = 1LL << 60; // 1.15e18constexpr int MOD = (int)1e9 + 7;void _main() {using mint = modint1000000007;int H, W;cin >> H >> W;vector<vector<char>> S1(H, vector<char>(W)), S2(W, vector<char>(H));rep(y, 0, H) rep(x, 0, W){char c;cin >> c;S1[y][x] = S2[x][y] = c;}auto func = [](int h, int w, vector<vector<char>>& s) -> pair<mint, int> {mint cnt = 1;vector<bool> chkr(2, true); // 市松模様か?rep(x, 0, w){vector<bool> pos(2, true); // 無矛盾か?rep(y, 0, h){if(s[y][x] == '0') pos[y % 2] = false;if(s[y][x] == '1') pos[(y + 1) % 2] = false;}if(!pos[0]) chkr[x % 2] = false;if(!pos[1]) chkr[(x + 1) % 2] = false;cnt *= (int)pos[0] + pos[1];}return {cnt, (int)chkr[0] + chkr[1]};};auto [cnt1, chkr1] = func(H, W, S1);auto [cnt2, chkr2] = func(W, H, S2);assert(chkr1 == chkr2);cout << (cnt1 + cnt2 - chkr1).val() << endl;}signed main() {cin.tie(nullptr); ios::sync_with_stdio(false);cout << fixed << setprecision(15); cerr << fixed << setprecision(15);_main();}