結果
問題 |
No.628 Tagの勢い
|
ユーザー |
|
提出日時 | 2019-06-23 05:29:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 1,961 bytes |
コンパイル時間 | 5,421 ms |
コンパイル使用メモリ | 87,756 KB |
実行使用メモリ | 48,264 KB |
最終ジャッジ日時 | 2024-12-26 10:19:37 |
合計ジャッジ時間 | 11,302 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.util.*; import java.io.*; import java.math.*; public class No628 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<String, Integer> map = new HashMap<String, Integer>(); for(int i = 0; i < n; i++) { int no = sc.nextInt(); int m = sc.nextInt(), s = sc.nextInt(); for(int j = 0; j < m; j++) { String t = sc.next(); if(map.containsKey(t)) map.put(t, map.get(t) + s); else map.put(t, s); } } ArrayList<Map.Entry<String, Integer>> al = new ArrayList<Map.Entry<String, Integer>>(); for(Map.Entry<String, Integer> entry : map.entrySet()) { al.add(entry); } Collections.sort(al, new Comparator<Map.Entry<String, Integer>>() { //compareを使用して値を比較する public int compare(Map.Entry<String, Integer> obj1, Map.Entry<String, Integer> obj2) { //降順 return obj2.getValue().compareTo(obj1.getValue()); } }); ArrayList<Integer> vl = new ArrayList<Integer>(); String[] k = new String[al.size()]; int[] v = new int[al.size()]; int c = 0; for(Map.Entry<String, Integer> entry : al) { vl.add(entry.getValue()); k[c] = entry.getKey(); v[c] = entry.getValue(); c++; } for(int i = 0; i < v.length; i++) { if(vl.indexOf(v[i]) != vl.lastIndexOf(v[i])) { int sa = vl.lastIndexOf(v[i]) - vl.indexOf(v[i]) + 1; String[] s = new String[sa]; for(int j = 0; j < sa; j++) { s[j] = k[vl.indexOf(v[i]) + j]; } Arrays.sort(s); for(int j = vl.indexOf(v[i]); j <= vl.lastIndexOf(v[i]); j++) { k[j] = s[j - vl.indexOf(v[i])]; } } } int max = v.length > 10? 10 : v.length; for(int i = 0; i < max; i++) { System.out.println(k[i] + " " + v[i]); } } }