結果

問題 No.1898 Battle and Exchange
ユーザー tentententen
提出日時 2022-04-11 14:51:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,588 bytes
コンパイル時間 2,876 ms
コンパイル使用メモリ 82,784 KB
実行使用メモリ 91,840 KB
最終ジャッジ日時 2024-12-15 10:48:01
合計ジャッジ時間 47,173 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
51,312 KB
testcase_01 AC 78 ms
51,060 KB
testcase_02 AC 78 ms
51,392 KB
testcase_03 AC 80 ms
50,968 KB
testcase_04 WA -
testcase_05 AC 112 ms
51,900 KB
testcase_06 WA -
testcase_07 AC 129 ms
52,148 KB
testcase_08 AC 110 ms
51,836 KB
testcase_09 AC 275 ms
57,140 KB
testcase_10 AC 80 ms
51,424 KB
testcase_11 AC 90 ms
51,332 KB
testcase_12 AC 173 ms
55,700 KB
testcase_13 AC 85 ms
51,372 KB
testcase_14 AC 137 ms
52,356 KB
testcase_15 AC 81 ms
51,072 KB
testcase_16 AC 129 ms
52,264 KB
testcase_17 AC 260 ms
56,484 KB
testcase_18 AC 633 ms
65,336 KB
testcase_19 AC 881 ms
67,880 KB
testcase_20 AC 583 ms
65,844 KB
testcase_21 AC 1,549 ms
81,816 KB
testcase_22 AC 96 ms
51,320 KB
testcase_23 AC 118 ms
51,800 KB
testcase_24 AC 121 ms
51,776 KB
testcase_25 AC 136 ms
52,156 KB
testcase_26 AC 81 ms
51,216 KB
testcase_27 AC 218 ms
55,808 KB
testcase_28 AC 233 ms
56,364 KB
testcase_29 AC 285 ms
57,672 KB
testcase_30 AC 197 ms
56,460 KB
testcase_31 AC 100 ms
51,480 KB
testcase_32 AC 504 ms
64,760 KB
testcase_33 WA -
testcase_34 AC 512 ms
64,456 KB
testcase_35 AC 591 ms
66,824 KB
testcase_36 AC 529 ms
66,768 KB
testcase_37 AC 411 ms
60,148 KB
testcase_38 AC 2,481 ms
81,080 KB
testcase_39 AC 1,088 ms
80,256 KB
testcase_40 AC 2,175 ms
78,532 KB
testcase_41 AC 999 ms
78,756 KB
testcase_42 AC 275 ms
57,044 KB
testcase_43 AC 826 ms
77,772 KB
testcase_44 AC 93 ms
51,284 KB
testcase_45 AC 384 ms
58,488 KB
testcase_46 AC 939 ms
65,376 KB
testcase_47 AC 315 ms
57,812 KB
testcase_48 AC 304 ms
56,776 KB
testcase_49 AC 222 ms
55,756 KB
testcase_50 AC 228 ms
55,856 KB
testcase_51 AC 235 ms
56,396 KB
testcase_52 AC 249 ms
57,400 KB
testcase_53 AC 486 ms
62,660 KB
testcase_54 AC 540 ms
62,828 KB
testcase_55 AC 694 ms
65,192 KB
testcase_56 AC 480 ms
64,680 KB
testcase_57 WA -
testcase_58 AC 1,797 ms
91,040 KB
testcase_59 AC 1,714 ms
91,200 KB
testcase_60 AC 1,758 ms
91,224 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();
        int m = sc.nextInt();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        Card[] cards = new Card[n];
        for (int i = 0; i < n; i++) {
            cards[i] = new Card(i, sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        int left = 0;
        int right = Integer.MAX_VALUE / 2;
        PriorityQueue<Card> queue = new PriorityQueue<>();
        while (right - left > 1) {
            int x = (left + right) / 2;
            Card current = new Card(-1, 1, 1, x);
            queue.clear();
            queue.add(cards[0]);
            boolean[] visited = new boolean[n];
            boolean[] added = new boolean[n];
            added[0] = true;
            while (queue.size() > 0 && current.getSum() > queue.peek().getSum() && !visited[n - 1]) {
                Card c = queue.poll();
                if (visited[c.idx]) {
                    continue;
                }
                visited[c.idx] = true;
                current.exchange(c);
                for (int y : graph.get(c.idx)) {
                    if (!added[y]) {
                        queue.add(cards[y]);
                        added[y] = true;
                    }
                }
            }
            if (visited[n - 1]) {
                right = x;
            } else {
                left = x;
            }
        }
        System.out.println("1 1 " + right);
    }
    
    static class Card implements Comparable<Card> {
        int idx;
        int[] values;
        
        public Card(int idx, int a, int b, int c) {
            this.idx = idx;
            values = new int[]{a, b, c};
            sort();
        }
        
        public void sort() {
            Arrays.sort(values);
        }
        
        public int getSum() {
            int sum = 0;
            for (int x : values) {
                sum += x;
            }
            return sum;
        }
        
        public int compareTo(Card another) {
            return getSum() - another.getSum();
        }
        
        public void exchange(Card another) {
            if (values[0] < another.values[1] && values[1] < another.values[2]) {
                values[0] = another.values[1];
                values[1] = another.values[2];
                sort();
            } else if (values[0] < another.values[2]) {
                values[0] = another.values[2];
                sort();
            }
        }
     }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0