結果
問題 | No.714 回転寿司屋のシミュレート |
ユーザー | tenten |
提出日時 | 2022-08-03 09:04:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 2,520 bytes |
コンパイル時間 | 6,870 ms |
コンパイル使用メモリ | 78,728 KB |
実行使用メモリ | 53,240 KB |
最終ジャッジ日時 | 2024-09-12 21:44:23 |
合計ジャッジ時間 | 7,183 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,336 KB |
testcase_01 | AC | 53 ms
50,536 KB |
testcase_02 | AC | 56 ms
50,528 KB |
testcase_03 | AC | 58 ms
50,280 KB |
testcase_04 | AC | 88 ms
51,336 KB |
testcase_05 | AC | 98 ms
52,428 KB |
testcase_06 | AC | 123 ms
52,764 KB |
testcase_07 | AC | 141 ms
52,816 KB |
testcase_08 | AC | 154 ms
53,240 KB |
testcase_09 | AC | 133 ms
52,776 KB |
testcase_10 | AC | 126 ms
52,788 KB |
testcase_11 | AC | 101 ms
52,140 KB |
testcase_12 | AC | 125 ms
52,600 KB |
testcase_13 | AC | 107 ms
52,192 KB |
testcase_14 | AC | 118 ms
52,516 KB |
testcase_15 | AC | 113 ms
52,184 KB |
testcase_16 | AC | 112 ms
51,888 KB |
testcase_17 | AC | 127 ms
52,972 KB |
testcase_18 | AC | 113 ms
52,692 KB |
testcase_19 | AC | 98 ms
52,044 KB |
testcase_20 | AC | 109 ms
52,360 KB |
testcase_21 | AC | 106 ms
52,168 KB |
testcase_22 | AC | 101 ms
51,648 KB |
testcase_23 | AC | 108 ms
51,872 KB |
testcase_24 | AC | 100 ms
51,328 KB |
testcase_25 | AC | 101 ms
51,536 KB |
testcase_26 | AC | 99 ms
51,220 KB |
testcase_27 | AC | 104 ms
51,424 KB |
testcase_28 | AC | 90 ms
51,408 KB |
testcase_29 | AC | 103 ms
52,096 KB |
testcase_30 | AC | 53 ms
50,136 KB |
testcase_31 | AC | 57 ms
50,108 KB |
testcase_32 | AC | 54 ms
50,152 KB |
testcase_33 | AC | 53 ms
50,388 KB |
testcase_34 | AC | 54 ms
50,404 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); Customer[] customers = new Customer[20]; StringBuilder sb = new StringBuilder(); while (n-- > 0) { int type = sc.nextInt(); if (type == 0) { int idx = sc.nextInt() - 1; Customer tmp = new Customer(idx); int count = sc.nextInt(); while (count-- > 0) { tmp.add(sc.next()); } customers[idx] = tmp; } else if (type == 1) { int idx = -1; String dish = sc.next(); for (Customer x : customers) { if (x != null && x.canEat(dish)) { idx = x.eat(dish); break; } } sb.append(idx).append("\n"); } else { customers[sc.nextInt() - 1] = null; } } System.out.print(sb); } static class Customer { int idx; HashMap<String, Integer> counts = new HashMap<>(); public Customer(int idx) { this.idx = idx; } public void add(String dish) { counts.put(dish, counts.getOrDefault(dish, 0) + 1); } public boolean canEat(String dish) { return counts.containsKey(dish); } public int eat(String dish) { if (counts.get(dish) == 1) { counts.remove(dish); } else { counts.put(dish, counts.get(dish) - 1); } return idx + 1; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }