結果

問題 No.957 植林
ユーザー htensaihtensai
提出日時 2020-02-12 11:33:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,538 bytes
コンパイル時間 2,769 ms
コンパイル使用メモリ 80,332 KB
実行使用メモリ 61,468 KB
最終ジャッジ日時 2024-04-14 08:25:27
合計ジャッジ時間 32,664 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
53,952 KB
testcase_01 AC 129 ms
54,268 KB
testcase_02 AC 129 ms
54,104 KB
testcase_03 AC 664 ms
59,832 KB
testcase_04 AC 640 ms
59,712 KB
testcase_05 AC 691 ms
59,880 KB
testcase_06 AC 693 ms
59,784 KB
testcase_07 AC 649 ms
59,504 KB
testcase_08 AC 657 ms
59,552 KB
testcase_09 AC 692 ms
59,916 KB
testcase_10 AC 638 ms
59,520 KB
testcase_11 AC 659 ms
59,356 KB
testcase_12 AC 675 ms
59,504 KB
testcase_13 AC 646 ms
59,660 KB
testcase_14 AC 687 ms
59,660 KB
testcase_15 AC 537 ms
58,136 KB
testcase_16 AC 617 ms
59,564 KB
testcase_17 AC 631 ms
59,604 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 585 ms
59,388 KB
testcase_42 AC 586 ms
59,368 KB
testcase_43 AC 702 ms
61,468 KB
testcase_44 AC 707 ms
61,260 KB
testcase_45 AC 130 ms
54,340 KB
testcase_46 AC 130 ms
53,860 KB
testcase_47 AC 131 ms
54,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] field = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                field[i][j] = sc.nextInt();
            }
        }
        int[] rows = new int[h];
        PriorityQueue<Type> queue = new PriorityQueue<>();
        PriorityQueue<Type> next = new PriorityQueue<>();
        for (int i = 0; i < h; i++) {
            rows[i] = sc.nextInt();
            long value = rows[i];
            for (int j = 0; j < w; j++) {
                value -= field[i][j];
            }
            queue.add(new Type(true, i, value));
        }
        int[] cals = new int[w];
        for (int i = 0; i < w; i++) {
            cals[i] = sc.nextInt();
            long value = cals[i];
            for (int j = 0; j < h; j++) {
                value -= field[j][i];
            }
            queue.add(new Type(false, i, value));
        }
        long total = 0;
        long max = 0;
        while (queue.size() > 0) {
            Type target = queue.poll();
            total += target.value;
            max = Math.max(max, total);
            while (queue.size() > 0) {
                Type tmp = queue.poll();
                if (target.isRow != tmp.isRow) {
                    if (target.isRow) {
                        tmp.value += field[target.idx][tmp.idx];
                    } else {
                        tmp.value += field[tmp.idx][target.idx];
                    }
                }
                next.add(tmp);
            }
            PriorityQueue<Type> t = next;
            next = queue;
            queue = t;
        }
        System.out.println(max);
    }
    
    static class Type implements Comparable<Type> {
        boolean isRow;
        int idx;
        long value;
        
        public Type(boolean isRow, int idx, long value) {
            this.isRow = isRow;
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Type another) {
            if (value < another.value) {
                return 1;
            } else if (value == another.value) {
                return 0;
            } else {
                return -1;
            }
        }
        
        public String toString() {
            return isRow + ":" + idx + ":" + value;
        }
   }
}
0