結果
| 問題 |
No.226 0-1パズル
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-06-12 22:46:56 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 5,000 ms |
| コード長 | 1,397 bytes |
| コンパイル時間 | 2,928 ms |
| コンパイル使用メモリ | 77,400 KB |
| 実行使用メモリ | 41,632 KB |
| 最終ジャッジ日時 | 2024-07-26 14:23:06 |
| 合計ジャッジ時間 | 6,284 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
package no226;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static long MOD = 1000000007;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int w = sc.nextInt();
char[][] m = new char[h][];
for(int i=0;i<h;i++) {
m[i] = sc.next().toCharArray();
}
long ans = count1(m) - count2(m);
char[][] mt = new char[w][h];
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
mt[j][i] = m[i][j];
}
}
ans += count1(mt);
System.out.println((ans % MOD + MOD)% MOD);
}
public static long count1(char[][] m) {
int h = m.length;
int w = m[0].length;
int[] check = new int[w];
Arrays.fill(check, 2);
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
if (m[i][j] != '?') {
int num = (m[i][j] - '0' + i) % 2;
if (check[j] != 2 && check[j] != num) {
return 0;
}
check[j] = num;
}
}
}
long ans = 1;
for(int i=0;i<w;i++) {
if (check[i] == 2) {
ans = (ans * 2) % MOD;
}
}
return ans;
}
public static long count2(char[][] m) {
int h = m.length;
int w = m[0].length;
int type = 2;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
if (m[i][j] != '?') {
int num = (m[i][j] - '0' + i + j) % 2;
if (type != 2 && num != type) {
return 0;
}
type = num;
}
}
}
return type == 2 ? 2 : 1;
}
}
ぴろず