結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー | Grenache |
提出日時 | 2015-12-17 23:20:42 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,118 bytes |
コンパイル時間 | 4,001 ms |
コンパイル使用メモリ | 79,304 KB |
実行使用メモリ | 39,284 KB |
最終ジャッジ日時 | 2024-09-16 07:42:11 |
合計ジャッジ時間 | 7,709 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
37,084 KB |
testcase_01 | AC | 56 ms
37,204 KB |
testcase_02 | AC | 54 ms
37,220 KB |
testcase_03 | AC | 53 ms
36,696 KB |
testcase_04 | AC | 75 ms
38,360 KB |
testcase_05 | AC | 87 ms
38,356 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 95 ms
39,064 KB |
testcase_09 | AC | 88 ms
39,284 KB |
testcase_10 | AC | 98 ms
39,028 KB |
testcase_11 | AC | 94 ms
38,968 KB |
testcase_12 | AC | 97 ms
39,032 KB |
testcase_13 | AC | 83 ms
38,656 KB |
testcase_14 | AC | 57 ms
36,940 KB |
testcase_15 | AC | 58 ms
37,460 KB |
testcase_16 | AC | 53 ms
37,224 KB |
testcase_17 | AC | 55 ms
37,200 KB |
testcase_18 | AC | 54 ms
37,284 KB |
testcase_19 | AC | 54 ms
37,060 KB |
testcase_20 | AC | 54 ms
37,172 KB |
testcase_21 | AC | 54 ms
37,204 KB |
testcase_22 | AC | 53 ms
37,300 KB |
testcase_23 | AC | 54 ms
37,080 KB |
testcase_24 | AC | 54 ms
37,204 KB |
testcase_25 | WA | - |
testcase_26 | AC | 54 ms
37,180 KB |
testcase_27 | WA | - |
testcase_28 | AC | 53 ms
36,836 KB |
testcase_29 | AC | 54 ms
37,344 KB |
testcase_30 | AC | 53 ms
37,108 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 (not[e.id] || (e.le != not[l]) || (e.re != not[r])) { continue; } not[e.id] = true; cnt++; if (!not[l]) { pq.add(new Pair(l)); } if (!not[r]) { 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); } } }