結果
| 問題 |
No.2094 Symmetry
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-10-11 09:51:16 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 767 ms / 2,000 ms |
| コード長 | 2,112 bytes |
| コンパイル時間 | 2,683 ms |
| コンパイル使用メモリ | 78,328 KB |
| 実行使用メモリ | 62,612 KB |
| 最終ジャッジ日時 | 2024-06-25 05:38:59 |
| 合計ジャッジ時間 | 21,559 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
long k = sc.nextLong();
int count = 0;
for (int i = 0; i < 2 * n; i++) {
for (char c : sc.next().toCharArray()) {
if (c == '#') {
count++;
}
}
}
PriorityQueue<Integer> first = new PriorityQueue<>();
int[][] values = new int[2 * n][2 * n];
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < 2 * n; j++) {
values[i][j] = sc.nextInt();
first.add(-values[i][j]);
}
}
long sum1 = 0;
for (int i = 0; i < count; i++) {
sum1 -= first.poll();
}
if (count % 2 == 1) {
System.out.println(sum1);
return;
}
PriorityQueue<Integer> second = new PriorityQueue<>();
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < n; j++) {
second.add(-(values[i][j] + values[i][2 * n - j - 1]));
}
}
long sum2 = 0;
for (int i = 0; i < count / 2; i++) {
sum2 -= second.poll();
}
System.out.println(Math.max(sum1, sum2 + k));
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten