結果
| 問題 |
No.628 Tagの勢い
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-06 12:47:16 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| コード長 | 1,463 bytes |
| コンパイル時間 | 3,435 ms |
| コンパイル使用メモリ | 85,824 KB |
| 実行使用メモリ | 46,404 KB |
| 最終ジャッジ日時 | 2024-10-07 22:20:08 |
| 合計ジャッジ時間 | 7,050 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.Map.*;
public class Main_yukicoder628 {
private static Scanner sc;
private static Printer pr;
private static void solve() {
int n = sc.nextInt();
Map<String, Integer> hm = new HashMap<>();
for (int i = 0; i < n; i++) {
@SuppressWarnings("unused")
int no = sc.nextInt();
int m = sc.nextInt();
int s = sc.nextInt();
for (int j = 0; j < m; j++) {
String tag = sc.next();
if (hm.containsKey(tag)) {
hm.put(tag, hm.get(tag) + s);
} else {
hm.put(tag, s);
}
}
}
List<Pair> ans = new ArrayList<>();
for (Entry<String, Integer> e : hm.entrySet()) {
ans.add(new Pair(e.getKey(), e.getValue()));
}
Collections.sort(ans);
for (int i = 0, size = ans.size(); i < 10 && i < size; i++) {
Pair e = ans.get(i);
pr.printf("%s %d\n", e.a, e.b);
}
}
private static class Pair implements Comparable<Pair> {
String a;
int b;
Pair(String a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(Pair o) {
if (b == o.b) {
return a.compareTo(o.a);
}
return Integer.compare(o.b, b);
}
}
// ---------------------------------------------------
public static void main(String[] args) {
sc = new Scanner(System.in);
pr = new Printer(System.out);
solve();
pr.close();
sc.close();
}
private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}