結果
問題 | No.1060 素敵な宝箱 |
ユーザー | tenten |
提出日時 | 2023-06-08 08:42:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 156 ms / 2,000 ms |
コード長 | 3,131 bytes |
コンパイル時間 | 2,722 ms |
コンパイル使用メモリ | 90,040 KB |
実行使用メモリ | 44,992 KB |
最終ジャッジ日時 | 2024-06-09 18:18:15 |
合計ジャッジ時間 | 7,508 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
36,792 KB |
testcase_01 | AC | 47 ms
37,092 KB |
testcase_02 | AC | 46 ms
37,200 KB |
testcase_03 | AC | 45 ms
37,028 KB |
testcase_04 | AC | 46 ms
37,156 KB |
testcase_05 | AC | 45 ms
36,804 KB |
testcase_06 | AC | 45 ms
36,820 KB |
testcase_07 | AC | 46 ms
37,000 KB |
testcase_08 | AC | 63 ms
38,184 KB |
testcase_09 | AC | 60 ms
38,152 KB |
testcase_10 | AC | 67 ms
37,816 KB |
testcase_11 | AC | 70 ms
37,916 KB |
testcase_12 | AC | 111 ms
40,264 KB |
testcase_13 | AC | 122 ms
41,668 KB |
testcase_14 | AC | 127 ms
42,208 KB |
testcase_15 | AC | 142 ms
44,704 KB |
testcase_16 | AC | 128 ms
42,872 KB |
testcase_17 | AC | 108 ms
40,020 KB |
testcase_18 | AC | 116 ms
40,968 KB |
testcase_19 | AC | 111 ms
41,352 KB |
testcase_20 | AC | 138 ms
43,176 KB |
testcase_21 | AC | 131 ms
43,576 KB |
testcase_22 | AC | 146 ms
43,560 KB |
testcase_23 | AC | 113 ms
40,952 KB |
testcase_24 | AC | 152 ms
44,992 KB |
testcase_25 | AC | 150 ms
44,924 KB |
testcase_26 | AC | 156 ms
44,808 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Box[] boxes = new Box[n]; int[] sums = new int[m]; for (int i = 0; i < n; i++) { int[] values = new int[m]; for (int j = 0; j < m; j++) { values[j] = sc.nextInt(); sums[j] += values[j]; } boxes[i] = new Box(values); } Box.values = sums; for (Box b : boxes) { b.calc(); } Arrays.sort(boxes); long[] ev = new long[m]; long[] od = new long[m]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { boxes[i].add(ev); } else { boxes[i].add(od); } } long ans = 0; for (int i = 0; i < m; i++) { ans -= ev[i] * ev[i] - od[i] * od[i]; } System.out.println(ans); } static class Box implements Comparable<Box> { static int[] values; int[] counts; long score; public Box(int[] counts) { this.counts = counts; } public void calc() { for (int i = 0; i < counts.length; i++) { score += values[i] * counts[i]; } } public int compareTo(Box another) { if (score == another.score) { return 0; } else if (score < another.score) { return -1; } else { return 1; } } public void add(long[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] += counts[i]; } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }