結果

問題 No.1898 Battle and Exchange
ユーザー tentententen
提出日時 2022-04-11 14:51:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,588 bytes
コンパイル時間 2,732 ms
コンパイル使用メモリ 81,968 KB
実行使用メモリ 80,140 KB
最終ジャッジ日時 2024-05-09 02:19:05
合計ジャッジ時間 49,454 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
38,476 KB
testcase_01 AC 70 ms
38,308 KB
testcase_02 AC 68 ms
38,120 KB
testcase_03 AC 70 ms
38,308 KB
testcase_04 WA -
testcase_05 AC 104 ms
38,996 KB
testcase_06 WA -
testcase_07 AC 122 ms
39,128 KB
testcase_08 AC 101 ms
38,752 KB
testcase_09 AC 274 ms
48,696 KB
testcase_10 AC 70 ms
38,092 KB
testcase_11 AC 83 ms
38,168 KB
testcase_12 AC 143 ms
40,388 KB
testcase_13 AC 72 ms
37,868 KB
testcase_14 AC 131 ms
39,880 KB
testcase_15 AC 71 ms
38,308 KB
testcase_16 AC 117 ms
39,388 KB
testcase_17 AC 250 ms
45,576 KB
testcase_18 AC 546 ms
50,996 KB
testcase_19 AC 1,005 ms
54,752 KB
testcase_20 AC 687 ms
55,616 KB
testcase_21 AC 1,661 ms
73,564 KB
testcase_22 AC 86 ms
38,380 KB
testcase_23 AC 112 ms
38,868 KB
testcase_24 AC 115 ms
39,144 KB
testcase_25 AC 137 ms
39,496 KB
testcase_26 AC 78 ms
38,152 KB
testcase_27 AC 220 ms
43,616 KB
testcase_28 AC 238 ms
44,120 KB
testcase_29 AC 313 ms
47,204 KB
testcase_30 AC 179 ms
41,892 KB
testcase_31 AC 100 ms
38,712 KB
testcase_32 AC 526 ms
54,832 KB
testcase_33 WA -
testcase_34 AC 454 ms
51,724 KB
testcase_35 AC 617 ms
56,964 KB
testcase_36 AC 565 ms
55,404 KB
testcase_37 AC 419 ms
49,120 KB
testcase_38 AC 2,345 ms
71,240 KB
testcase_39 AC 1,039 ms
66,952 KB
testcase_40 AC 2,208 ms
68,452 KB
testcase_41 AC 1,243 ms
66,052 KB
testcase_42 AC 287 ms
45,528 KB
testcase_43 AC 940 ms
64,068 KB
testcase_44 AC 91 ms
38,580 KB
testcase_45 AC 397 ms
48,632 KB
testcase_46 AC 1,019 ms
56,004 KB
testcase_47 AC 325 ms
45,884 KB
testcase_48 AC 332 ms
49,836 KB
testcase_49 AC 223 ms
42,660 KB
testcase_50 AC 203 ms
43,076 KB
testcase_51 AC 217 ms
44,144 KB
testcase_52 AC 236 ms
45,620 KB
testcase_53 AC 447 ms
52,228 KB
testcase_54 AC 576 ms
53,164 KB
testcase_55 AC 820 ms
54,624 KB
testcase_56 AC 528 ms
52,580 KB
testcase_57 WA -
testcase_58 AC 1,920 ms
76,028 KB
testcase_59 AC 1,959 ms
80,140 KB
testcase_60 AC 2,088 ms
75,464 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