結果

問題 No.433 ICPC国内予選の選抜ルールがこんな感じだったらうれしい
ユーザー hermione17hermione17
提出日時 2016-10-14 23:50:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,534 ms / 4,000 ms
コード長 2,137 bytes
コンパイル時間 6,271 ms
コンパイル使用メモリ 76,500 KB
実行使用メモリ 76,524 KB
最終ジャッジ日時 2023-08-14 11:03:30
合計ジャッジ時間 49,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,501 ms
70,112 KB
testcase_01 AC 1,402 ms
70,200 KB
testcase_02 AC 1,030 ms
63,164 KB
testcase_03 AC 1,166 ms
59,448 KB
testcase_04 AC 1,151 ms
59,060 KB
testcase_05 AC 1,185 ms
64,864 KB
testcase_06 AC 1,534 ms
76,196 KB
testcase_07 AC 1,155 ms
64,376 KB
testcase_08 AC 1,064 ms
65,116 KB
testcase_09 AC 1,000 ms
64,240 KB
testcase_10 AC 1,033 ms
66,648 KB
testcase_11 AC 1,162 ms
65,944 KB
testcase_12 AC 1,130 ms
70,496 KB
testcase_13 AC 930 ms
61,472 KB
testcase_14 AC 1,025 ms
63,608 KB
testcase_15 AC 846 ms
58,484 KB
testcase_16 AC 1,249 ms
68,048 KB
testcase_17 AC 1,098 ms
59,872 KB
testcase_18 AC 1,115 ms
62,180 KB
testcase_19 AC 893 ms
61,296 KB
testcase_20 AC 965 ms
60,448 KB
testcase_21 AC 918 ms
61,600 KB
testcase_22 AC 1,075 ms
69,816 KB
testcase_23 AC 1,000 ms
65,300 KB
testcase_24 AC 859 ms
61,368 KB
testcase_25 AC 1,039 ms
67,748 KB
testcase_26 AC 913 ms
61,336 KB
testcase_27 AC 1,033 ms
65,856 KB
testcase_28 AC 879 ms
59,516 KB
testcase_29 AC 1,056 ms
63,564 KB
testcase_30 AC 125 ms
46,616 KB
testcase_31 AC 121 ms
45,888 KB
testcase_32 AC 1,204 ms
75,072 KB
testcase_33 AC 1,311 ms
76,524 KB
testcase_34 AC 960 ms
58,944 KB
testcase_35 AC 124 ms
45,768 KB
testcase_36 AC 125 ms
46,124 KB
testcase_37 AC 146 ms
46,432 KB
testcase_38 AC 144 ms
45,892 KB
testcase_39 AC 216 ms
49,668 KB
testcase_40 AC 221 ms
49,544 KB
testcase_41 AC 365 ms
51,516 KB
testcase_42 AC 354 ms
51,364 KB
testcase_43 AC 377 ms
51,392 KB
testcase_44 AC 370 ms
51,852 KB
testcase_45 AC 240 ms
50,300 KB
testcase_46 AC 427 ms
51,468 KB
testcase_47 AC 435 ms
52,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Y433 {
	Y433() throws Exception {
		Scanner in = new Scanner(System.in);
		PrintStream out = new PrintStream(System.out);
		
		int n = in.nextInt();
		int k = in.nextInt();
		
		School[] school = new School[100001];
		for (int i = 0; i < 100001; i++) {
			school[i] = new School();			
		}
		
		for (int i = 0; i < n; i++) {
			int s = in.nextInt();
			int p = in.nextInt();
			int u = in.nextInt();
			school[u].add(new Team(s, p, i));
		}
	

		PriorityQueue<School> pq = new PriorityQueue<>();

		for (int i = 0; i < 100001; i++) {
			if (school[i].teams.size() > 0) {
				school[i].sort();
				pq.add(school[i]);
			}
		}

		for (int i = 0; i < k; i++) {
			School sch = pq.poll();
			Team team = sch.getLast();
			
			out.println(sch.getLast().name);
			sch.pop();
			if (sch.teams.size() > 0) {
				pq.add(sch);
			}
		}
		

	}
	
	class Team implements Comparable {
		int s, p, name;
		
		Team(int s, int p, int name) {
			this.s = s;
			this.p = p;
			this.name = name;
		}

		@Override
		public int compareTo(Object o) {
			Team that = (Team) o;
			if (s != that.s) return Integer.compare(s, that.s);
			return Integer.compare(that.p, p);
		}
	}

	class School implements Comparable {

		int passed;
		List<Team> teams;
		
		School() {
			passed = 0;
			teams = new ArrayList();
		}

		void add(Team t) {
			teams.add(t);
		}
		
		Team pop() {
			Team team = getLast();
			teams.remove(teams.size() - 1);
			passed++;
			return team;
		}
		
		void sort() {
			teams.sort(null);
		}
		
		Team getLast() {
			return teams.get(teams.size() - 1);
		}
		
		@Override
		public int compareTo(Object o) {
			School that = (School) o;
			
			if (getLast().s != that.getLast().s) return Integer.compare(that.getLast().s, getLast().s);
			if (passed != that.passed) return Integer.compare(passed, that.passed);  
			return Integer.compare(getLast().p, that.getLast().p);
		}
		
	}
	
	public static void main(String argv[]) throws Exception {
		new Y433();
	}
}
0