結果

問題 No.3512 moesode
コンテスト
ユーザー ks2m
提出日時 2026-04-24 22:52:59
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 1,205 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,525 ms
コンパイル使用メモリ 84,840 KB
実行使用メモリ 61,776 KB
最終ジャッジ日時 2026-04-24 22:53:26
合計ジャッジ時間 15,443 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int k = Integer.parseInt(sa[2]);
		int[] in = new int[n];
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			in[b]++;
			set.add(a);
		}
		br.close();

		long ans = 0;
		for (int e : set) {
			ans += k - in[e];
		}

		if (set.size() <= k) {
			PriorityQueue<Obj> que = new PriorityQueue<>((o1, o2) -> o2.in - o1.in);
			for (int i = 0; i < n; i++) {
				if (!set.contains(i)) {
					Obj o = new Obj();
					o.i = i;
					o.in = in[i];
					que.add(o);
				}
			}
			int rem = k + 1 - set.size();
			for (int i = 0; i < rem; i++) {
				Obj o = que.poll();
				ans += k - o.in;
			}
		}
		System.out.println(ans);
	}

	static class Obj {
		int i, in;
	}
}
0