結果

問題 No.2094 Symmetry
ユーザー tentententen
提出日時 2022-10-11 09:51:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 841 ms / 2,000 ms
コード長 2,112 bytes
コンパイル時間 3,236 ms
コンパイル使用メモリ 75,468 KB
実行使用メモリ 73,540 KB
最終ジャッジ日時 2023-09-07 11:29:04
合計ジャッジ時間 23,402 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,472 KB
testcase_01 AC 44 ms
49,420 KB
testcase_02 AC 44 ms
49,584 KB
testcase_03 AC 43 ms
49,468 KB
testcase_04 AC 44 ms
49,472 KB
testcase_05 AC 47 ms
49,420 KB
testcase_06 AC 45 ms
49,576 KB
testcase_07 AC 45 ms
49,492 KB
testcase_08 AC 45 ms
49,504 KB
testcase_09 AC 752 ms
72,000 KB
testcase_10 AC 699 ms
72,296 KB
testcase_11 AC 759 ms
70,396 KB
testcase_12 AC 739 ms
71,636 KB
testcase_13 AC 649 ms
69,852 KB
testcase_14 AC 841 ms
73,540 KB
testcase_15 AC 800 ms
71,904 KB
testcase_16 AC 723 ms
71,652 KB
testcase_17 AC 635 ms
69,320 KB
testcase_18 AC 670 ms
69,672 KB
testcase_19 AC 735 ms
70,188 KB
testcase_20 AC 745 ms
71,896 KB
testcase_21 AC 765 ms
71,448 KB
testcase_22 AC 715 ms
72,068 KB
testcase_23 AC 682 ms
69,552 KB
testcase_24 AC 664 ms
69,548 KB
testcase_25 AC 704 ms
71,904 KB
testcase_26 AC 698 ms
71,844 KB
testcase_27 AC 44 ms
49,460 KB
testcase_28 AC 388 ms
67,596 KB
testcase_29 AC 44 ms
49,612 KB
testcase_30 AC 475 ms
68,612 KB
testcase_31 AC 440 ms
67,956 KB
testcase_32 AC 506 ms
71,276 KB
testcase_33 AC 46 ms
49,512 KB
testcase_34 AC 538 ms
70,432 KB
testcase_35 AC 546 ms
69,196 KB
testcase_36 AC 643 ms
68,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0