結果
問題 | No.2804 Fixer And Ratism |
ユーザー | tenten |
提出日時 | 2024-07-17 09:50:30 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,993 bytes |
コンパイル時間 | 5,739 ms |
コンパイル使用メモリ | 83,532 KB |
実行使用メモリ | 61,440 KB |
最終ジャッジ日時 | 2024-07-17 09:51:15 |
合計ジャッジ時間 | 18,360 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
50,872 KB |
testcase_01 | AC | 71 ms
51,260 KB |
testcase_02 | AC | 71 ms
51,136 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 168 ms
53,632 KB |
testcase_10 | WA | - |
testcase_11 | AC | 414 ms
59,352 KB |
testcase_12 | WA | - |
testcase_13 | AC | 225 ms
57,676 KB |
testcase_14 | AC | 357 ms
59,280 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 257 ms
59,296 KB |
testcase_18 | WA | - |
testcase_19 | AC | 148 ms
54,060 KB |
testcase_20 | WA | - |
testcase_21 | AC | 424 ms
59,356 KB |
testcase_22 | WA | - |
testcase_23 | AC | 487 ms
59,604 KB |
testcase_24 | WA | - |
testcase_25 | AC | 463 ms
59,420 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 470 ms
59,508 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 493 ms
59,196 KB |
testcase_33 | WA | - |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); TreeSet<Student> students = new TreeSet<>(); Map<String, Student> map = new HashMap<>(); List<Student> ans = new ArrayList<>(); while (q-- > 0) { int type = sc.nextInt(); if (type == 1) { String name = sc.next(); int rate = sc.nextInt(); map.put(name, new Student(name, rate)); students.add(map.get(name)); while (students.size() > n) { ans.add(students.pollLast()); } } else if (type == 2) { n -= sc.nextInt(); while (students.size() > n) { ans.add(students.pollLast()); } } else { String name = sc.next(); n += sc.nextInt(); students.remove(map.get(name)); map.get(name).fix(); students.add(map.get(name)); } } System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n"))); } static class Student implements Comparable<Student> { String name; int value; int fixed; public Student(String name, int value) { this.name = name; this.value = value; } public void fix() { fixed = 1; } public int hashCode() { return name.hashCode(); } public boolean equals(Object o) { Student s = (Student)o; return name.equals(s.name); } public int compareTo(Student another) { return fixed == another.fixed ? another.value - value : another.fixed - fixed; } public String toString() { return name; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }