結果
問題 | No.2094 Symmetry |
ユーザー | ks2m |
提出日時 | 2022-10-07 21:37:57 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 604 ms / 2,000 ms |
コード長 | 1,454 bytes |
コンパイル時間 | 2,703 ms |
コンパイル使用メモリ | 79,172 KB |
実行使用メモリ | 58,380 KB |
最終ジャッジ日時 | 2024-06-12 06:34:31 |
合計ジャッジ時間 | 17,450 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Collections; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); long k = Long.parseLong(sa[1]); int n2 = n * 2; char[][] s = new char[n2][n2]; for (int i = 0; i < n2; i++) { s[i] = br.readLine().toCharArray(); } int[][] c = new int[n2][n2]; for (int i = 0; i < n2; i++) { sa = br.readLine().split(" "); for (int j = 0; j < n2; j++) { c[i][j] = Integer.parseInt(sa[j]); } } br.close(); int b = 0; for (int i = 0; i < n2; i++) { for (int j = 0; j < n2; j++) { if (s[i][j] == '#') { b++; } } } PriorityQueue<Integer> que1 = new PriorityQueue<>(Collections.reverseOrder()); PriorityQueue<Integer> que2 = new PriorityQueue<>(Collections.reverseOrder()); for (int i = 0; i < n2; i++) { for (int j = 0; j < n2; j++) { que1.add(c[i][j]); } for (int j = 0; j < n; j++) { que2.add(c[i][j] + c[i][n2 - 1 - j]); } } long ans = 0; for (int i = 0; i < b; i++) { ans += que1.poll(); } if (b % 2 == 0) { int b2 = b / 2; long val = 0; for (int i = 0; i < b2; i++) { val += que2.poll(); } ans = Math.max(ans, val + k); } System.out.println(ans); } }