結果

問題 No.433 ICPC国内予選の選抜ルールがこんな感じだったらうれしい
ユーザー htensai
提出日時 2020-05-12 10:25:56
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,323 ms / 4,000 ms
コード長 1,963 bytes
コンパイル時間 3,724 ms
コンパイル使用メモリ 80,324 KB
実行使用メモリ 87,164 KB
最終ジャッジ日時 2024-07-23 20:35:10
合計ジャッジ時間 49,699 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		HashMap<Integer, PriorityQueue<Team>> all = new HashMap<>();
		for (int i = 0; i < n; i++) {
		    Team t = new Team(i, sc.nextInt(), sc.nextInt(), sc.nextInt());
		    if (!all.containsKey(t.univ)) {
		        all.put(t.univ, new PriorityQueue<>());
		    }
		    all.get(t.univ).add(t);
		}
		PriorityQueue<Team> queue = new PriorityQueue<>();
		for (PriorityQueue<Team> tmp : all.values()) {
		    int idx = 0;
		    while (tmp.size() > 0) {
		        Team t = tmp.poll();
		        t.rank = idx;
		        idx++;
		        queue.add(t);
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < k; i++) {
		    sb.append(queue.poll().idx).append("\n");
		}
		System.out.print(sb);
	}
	
	static int dfw(int x) {
	    if (x < 10) {
	        return x;
	    }
	    if (dp[x] != -1) {
	        return dp[x];
	    }
	    int prev = x % 10;
	    x /= 10;
	    int next = 0;
	    while (x > 0) {
	        int cur = x % 10;
	        x /= 10;
	        next *= 10;
	        next += (prev + cur) % 10 + (prev + cur) / 10;
	        prev = cur;
	    }
	    dp[x] = dfw(next);
	    return dp[x];
	}
	
	static class Team implements Comparable<Team> {
	    int idx;
	    int score;
	    int penalty;
	    int univ;
	    int rank;
	    
	    public Team(int idx, int score, int penalty, int univ) {
	        this.idx = idx;
	        this.score = score;
	        this.penalty = penalty;
	        this.univ = univ;
	    }
	    
	    public int compareTo(Team another) {
	        if (score == another.score) {
	            if (rank == another.rank) {
	                return penalty - another.penalty;
	            } else {
	                return rank - another.rank;
	            }
	        } else {
	            return another.score - score;
	        }
	    }
	}
}
0