結果
問題 | No.226 0-1パズル |
ユーザー | ぴろず |
提出日時 | 2015-06-12 22:46:56 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 154 ms / 5,000 ms |
コード長 | 1,397 bytes |
コンパイル時間 | 6,983 ms |
コンパイル使用メモリ | 78,844 KB |
実行使用メモリ | 56,796 KB |
最終ジャッジ日時 | 2023-10-04 12:07:14 |
合計ジャッジ時間 | 8,539 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 122 ms
56,092 KB |
testcase_01 | AC | 124 ms
55,728 KB |
testcase_02 | AC | 124 ms
56,192 KB |
testcase_03 | AC | 124 ms
55,744 KB |
testcase_04 | AC | 132 ms
55,796 KB |
testcase_05 | AC | 124 ms
55,728 KB |
testcase_06 | AC | 122 ms
55,756 KB |
testcase_07 | AC | 124 ms
55,904 KB |
testcase_08 | AC | 125 ms
55,788 KB |
testcase_09 | AC | 123 ms
55,836 KB |
testcase_10 | AC | 124 ms
56,000 KB |
testcase_11 | AC | 126 ms
55,708 KB |
testcase_12 | AC | 123 ms
56,104 KB |
testcase_13 | AC | 125 ms
55,672 KB |
testcase_14 | AC | 126 ms
56,080 KB |
testcase_15 | AC | 124 ms
55,820 KB |
testcase_16 | AC | 124 ms
55,816 KB |
testcase_17 | AC | 152 ms
56,796 KB |
testcase_18 | AC | 153 ms
56,500 KB |
testcase_19 | AC | 153 ms
56,256 KB |
testcase_20 | AC | 154 ms
56,592 KB |
testcase_21 | AC | 153 ms
56,544 KB |
ソースコード
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; } }