結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー | Grenache |
提出日時 | 2015-12-17 22:12:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,101 bytes |
コンパイル時間 | 4,106 ms |
コンパイル使用メモリ | 79,316 KB |
実行使用メモリ | 39,096 KB |
最終ジャッジ日時 | 2024-09-16 07:39:45 |
合計ジャッジ時間 | 7,761 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
36,856 KB |
testcase_01 | AC | 51 ms
36,836 KB |
testcase_02 | AC | 50 ms
37,092 KB |
testcase_03 | AC | 49 ms
36,736 KB |
testcase_04 | AC | 63 ms
38,352 KB |
testcase_05 | AC | 69 ms
38,396 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 85 ms
38,844 KB |
testcase_09 | AC | 78 ms
38,864 KB |
testcase_10 | AC | 90 ms
38,964 KB |
testcase_11 | AC | 96 ms
39,096 KB |
testcase_12 | AC | 88 ms
38,792 KB |
testcase_13 | AC | 87 ms
38,848 KB |
testcase_14 | AC | 56 ms
36,904 KB |
testcase_15 | AC | 57 ms
37,076 KB |
testcase_16 | AC | 50 ms
37,288 KB |
testcase_17 | AC | 49 ms
36,904 KB |
testcase_18 | AC | 49 ms
36,676 KB |
testcase_19 | AC | 49 ms
36,840 KB |
testcase_20 | AC | 48 ms
37,168 KB |
testcase_21 | AC | 54 ms
36,832 KB |
testcase_22 | AC | 53 ms
36,748 KB |
testcase_23 | AC | 54 ms
36,828 KB |
testcase_24 | AC | 54 ms
36,940 KB |
testcase_25 | WA | - |
testcase_26 | AC | 54 ms
37,092 KB |
testcase_27 | WA | - |
testcase_28 | AC | 54 ms
37,188 KB |
testcase_29 | AC | 54 ms
37,104 KB |
testcase_30 | AC | 53 ms
36,952 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; import java.util.PriorityQueue; public class Main_yukicoder324 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); n = sc.nextInt(); int m = sc.nextInt(); w = new int[n]; not = new boolean[n]; PriorityQueue<Pair> pq = new PriorityQueue<Pair>(); for (int i = 0; i < n; i++) { w[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { pq.add(new Pair(i)); } int cnt = 0; while (cnt < n - m) { Pair e = pq.remove(); int l = (e.id - 1 + n) % n; int r = (e.id + 1 + n) % n; if ((e.le != not[l]) || (e.re != not[r])) { continue; } not[e.id] = true; cnt++; if (!e.le) { pq.add(new Pair(l)); } if (!e.re) { pq.add(new Pair(r)); } } int ret = 0; for (int i = 0; i < n; i++) { if (!not[i]) { int l = (i - 1 + n) % n; int r = (i + 1 + n) % n; if (!not[l]) { ret += w[l]; } if (!not[r]) { ret += w[i]; } } } pr.println(ret / 2); pr.close(); sc.close(); } private static int n; private static int[] w; private static boolean[] not; private static class Pair implements Comparable<Pair> { int id; int sum; boolean le; boolean re; Pair(int id) { this.id = id; int l = (id - 1 + n) % n; int r = (id + 1 + n) % n; sum = (not[l] ? 0 : w[l]) + (not[r] ? 0 : w[id]); le = not[l]; re = not[r]; } @Override public int compareTo(Pair o) { return Integer.compare(this.sum, o.sum); } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }