結果
| 問題 |
No.628 Tagの勢い
|
| コンテスト | |
| ユーザー |
kohaku_kohaku
|
| 提出日時 | 2018-01-05 22:20:25 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 299 ms / 2,000 ms |
| コード長 | 2,063 bytes |
| コンパイル時間 | 2,365 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 48,640 KB |
| 最終ジャッジ日時 | 2024-10-07 22:15:01 |
| 合計ジャッジ時間 | 6,950 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TagList tl = new TagList();
int n = sc.nextInt();
for(int i = 0; i < n; i++) {
int no = sc.nextInt();
int m = sc.nextInt();
int s = sc.nextInt();
for(int j = 0; j < m; j++) {
String tag = sc.next();
int index = tl.getIndex(tag);
if(index== -1) {
tl.getList().add(new Tag(tag,s));
} else {
tl.getList().get(index).add(s);
}
}
}
tl.sort();
for(int i = 0; i < Math.min(10,tl.getList().size()); i++) {
Tag tmp = tl.getList().get(i);
System.out.println( tmp.getTag() + " " + tmp.getScore() );
}
}
}
class TagList {
List<Tag> list = new ArrayList<>();
public int getIndex(String tag) {
for(int i = 0; i < list.size(); i++) {
if(tag.equals(this.list.get(i).getTag())) {
return i;
}
}
return -1;
}
public List<Tag> getList() {
return this.list;
}
public void sort() {
Collections.sort(list, new TagStringComparator());
Collections.sort(list, new TagScoreComparator());
}
}
class Tag {
public String tag;
public int score;
public Tag(String tag, int score) {
this.tag = tag;
this.score = score;
}
public String getTag() {
return this.tag;
}
public int getScore() {
return this.score;
}
public void add(int add) {
this.score += add;
}
}
class TagStringComparator implements Comparator<Tag> {
public int compare(Tag t1, Tag t2){
return t1.getTag().compareTo(t2.getTag());
}
}
class TagScoreComparator implements Comparator<Tag> {
public int compare(Tag t1, Tag t2){
return t2.getScore() - t1.getScore();
}
}
kohaku_kohaku