結果
問題 | No.640 76本のトロンボーン |
ユーザー | 37zigen |
提出日時 | 2018-05-30 23:25:00 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 1,903 bytes |
コンパイル時間 | 3,655 ms |
コンパイル使用メモリ | 74,424 KB |
実行使用メモリ | 56,652 KB |
最終ジャッジ日時 | 2023-09-27 23:01:26 |
合計ジャッジ時間 | 6,715 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
55,900 KB |
testcase_01 | AC | 122 ms
55,620 KB |
testcase_02 | AC | 123 ms
55,948 KB |
testcase_03 | AC | 126 ms
55,788 KB |
testcase_04 | AC | 123 ms
56,220 KB |
testcase_05 | AC | 124 ms
55,412 KB |
testcase_06 | AC | 152 ms
56,016 KB |
testcase_07 | AC | 151 ms
56,224 KB |
testcase_08 | AC | 157 ms
56,340 KB |
testcase_09 | AC | 150 ms
56,652 KB |
testcase_10 | AC | 154 ms
56,312 KB |
testcase_11 | AC | 151 ms
55,924 KB |
testcase_12 | AC | 153 ms
56,548 KB |
testcase_13 | AC | 122 ms
56,064 KB |
testcase_14 | AC | 141 ms
55,916 KB |
testcase_15 | AC | 126 ms
55,656 KB |
testcase_16 | AC | 125 ms
55,792 KB |
ソースコード
import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner; public class Main { void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); char[][] s = new char[N][N]; for (int i = 0; i < N; ++i) { s[i] = sc.next().toCharArray(); } int ans = 0; { boolean f = true; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (i == 0 || i == N - 1 || j == 0 || j == N - 1) { f &= s[i][j] == '.'; } } } if (f) ans = 4; } for (int t = 0; t < 2; ++t) { ans = Math.max(solve(s), ans); for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { char tmp = s[i][j]; s[i][j] = s[j][i]; s[j][i] = tmp; } } } System.out.println(ans); } int solve(char[][] s) { int N = s.length; int ret = 0; for (int i = 0; i < N; i += N - 1) { for (int d = 0; d <= 1; ++d) { char[][] s2 = new char[N][N]; for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) s2[j][k] = s[j][k]; boolean flag = true; ret = Math.max(ret, go(s2)); for (int j = d; j < N - 1 + d; ++j) { flag &= s2[i][j] == '.'; s2[i][j] = '#'; } ret = Math.max(ret, (flag ? 1 : 0) + go(s2)); } } return ret; } int go(char[][] s) { int ret = 0; int N = s.length; for (int i = 0; i < N; ++i) { boolean flag = true; for (int j = 1; j < N - 1; ++j) { flag &= s[j][i] == '.'; } if (flag && (s[0][i] == '.' || s[N - 1][i] == '.')) { ++ret; } } return ret; } public static void main(String[] args) { new Main().run(); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } void show(char[][] s) { int N = s.length; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { System.out.print(s[i][j]); } System.out.println(); } } }