結果
問題 |
No.3235 巡回減算
|
ユーザー |
![]() |
提出日時 | 2025-08-15 23:10:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 687 ms / 10,000 ms |
コード長 | 1,106 bytes |
コンパイル時間 | 2,673 ms |
コンパイル使用メモリ | 79,752 KB |
実行使用メモリ | 46,608 KB |
最終ジャッジ日時 | 2025-08-15 23:11:06 |
合計ジャッジ時間 | 17,272 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { static int n = 8; static int[][] a; static int[] c; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[][] s = new char[n][n]; for (int i = 0; i < n; i++) { s[i] = br.readLine().toCharArray(); } br.close(); a = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = s[i][j] - '0'; } } c = new int[n]; if (dfs(1, new int[n])) { System.out.println("Yes"); } else { System.out.println("No"); } } static boolean dfs(int x, int[] b) { if (x == n) { System.arraycopy(a[0], 0, c, 0, n); for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) { c[(b[i] + j) % n] -= a[i][j]; } } boolean flg = true; for (int j = 0; j < n; j++) { if (c[j] != 0) { flg = false; break; } } return flg; } for (int i = 0; i < n; i++) { b[x] = i; if (dfs(x + 1, b)) { return true; } } return false; } }