結果

問題 No.226 0-1パズル
ユーザー Yang33Yang33
提出日時 2018-08-24 14:42:28
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,687 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 168,156 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-26 14:24:11
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/08/24 Problem: yukicoder 226 / Link: http://yukicoder.me/problems/no/226 ----- */
/* ------------
---------- */
/* ----------
DP
-------- */
template<class T>void rotate2dR(vector<vector<T>>& a) { // rorateToR
vector<vector<T>> res(a[0].size(), vector<T>(a.size()));
FOR(i, 0, (int)a.size())FOR(j, 0, (int)a[0].size())res[j][a.size() - i - 1] = a[i][j];
a = res;
}
LL decideTopGrid(const vector<vector<char>>& a) {
LL ret = 1; // e
int H = SZ(a), W = SZ(a[0]);
// 2^W
FOR(j, 0, W) {
int state = 0;
FOR(b, 0, 2) {
char top = '0' + b;
if (isdigit(a[0][j]) && a[0][j] != top)continue;
bool ok = 1;
FOR(i, 1, H) {
if (a[i][j] == '?')continue;
if (i & 1)ok &= (a[i][j] != top);
else ok &= (a[i][j] == top);
}
state += ok;
}
ret *= state;
ret %= MOD;
}
return ret;
}
// [0,2]
LL countCheckeredPattern(const vector<vector<char>>& a) {
int H = SZ(a), W = SZ(a[0]);
LL ret = 0;
FOR(b, 0, 2) {
bool ok = 1;
char top = '0' + b;
if (a[0][0] == '?' || a[0][0] == top) {
FOR(j, 0, W) {
FOR(i, 0, H) {
if (a[i][j] == '?')continue;
if ((i^j) & 1) {
ok &= (a[i][j] != top);
}
else {
ok &= (a[i][j] == top);
}
}
}
ret += ok;
}
}
return ret;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int H, W; cin >> H >> W;
vector<vector<char>>a(H, vector<char>(W));
FOR(i, 0, H) {
FOR(j, 0, W) {
cin >> a[i][j];
}
}
LL ans = decideTopGrid(a);
rotate2dR(a);
ans += decideTopGrid(a);
ans %= MOD;
ans -= countCheckeredPattern(a);
ans += MOD; ans %= MOD;
cout << ans << "\n";
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0