結果

問題 No.628 Tagの勢い
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2018-01-05 22:20:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 2,063 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 80,516 KB
実行使用メモリ 48,840 KB
最終ジャッジ日時 2024-04-16 20:01:11
合計ジャッジ時間 6,670 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
42,720 KB
testcase_01 AC 162 ms
42,916 KB
testcase_02 AC 162 ms
42,748 KB
testcase_03 AC 166 ms
43,076 KB
testcase_04 AC 155 ms
42,840 KB
testcase_05 AC 138 ms
42,532 KB
testcase_06 AC 152 ms
42,716 KB
testcase_07 AC 160 ms
42,888 KB
testcase_08 AC 163 ms
43,100 KB
testcase_09 AC 163 ms
42,468 KB
testcase_10 AC 188 ms
42,840 KB
testcase_11 AC 163 ms
42,992 KB
testcase_12 AC 285 ms
48,680 KB
testcase_13 AC 289 ms
48,840 KB
testcase_14 AC 281 ms
48,700 KB
testcase_15 AC 280 ms
48,496 KB
testcase_16 AC 270 ms
47,936 KB
testcase_17 AC 162 ms
42,784 KB
testcase_18 AC 162 ms
42,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0