結果
問題 |
No.714 回転寿司屋のシミュレート
|
ユーザー |
![]() |
提出日時 | 2020-10-14 13:31:41 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 1,690 bytes |
コンパイル時間 | 2,197 ms |
コンパイル使用メモリ | 79,256 KB |
実行使用メモリ | 46,832 KB |
最終ジャッジ日時 | 2024-07-20 19:06:52 |
合計ジャッジ時間 | 10,321 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Customer[] customers = new Customer[20]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int type = sc.nextInt(); if (type == 1) { boolean eated = false; String sushi = sc.next(); for (int j = 0; j < 20; j++) { if (customers[j] != null && customers[j].hasEat(sushi)) { sb.append(j + 1).append("\n"); eated = true; break; } } if (!eated) { sb.append(-1).append("\n"); } } else if (type == 0) { int idx = sc.nextInt() - 1; customers[idx] = new Customer(); int count = sc.nextInt(); for (int j = 0; j < count; j++) { customers[idx].add(sc.next()); } } else { customers[sc.nextInt() - 1] = null; } } System.out.print(sb); } static class Customer { HashMap<String, Integer> map = new HashMap<>(); public void add(String sushi) { map.put(sushi, map.getOrDefault(sushi, 0) + 1); } public boolean hasEat(String sushi) { if (map.containsKey(sushi)) { if (map.get(sushi) == 1) { map.remove(sushi); } else { map.put(sushi, map.get(sushi) - 1); } return true; } else { return false; } } } }