結果

問題 No.714 回転寿司屋のシミュレート
ユーザー tenten
提出日時 2022-08-03 09:04:55
言語 Java
(openjdk 23)
結果
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
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

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