結果

問題 No.714 回転寿司屋のシミュレート
ユーザー tentententen
提出日時 2022-08-03 09:04:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 2,520 bytes
コンパイル時間 3,776 ms
コンパイル使用メモリ 75,136 KB
実行使用メモリ 53,360 KB
最終ジャッジ日時 2023-10-09 23:17:02
合計ジャッジ時間 8,917 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,344 KB
testcase_01 AC 46 ms
49,300 KB
testcase_02 AC 49 ms
49,864 KB
testcase_03 AC 52 ms
49,352 KB
testcase_04 AC 77 ms
51,368 KB
testcase_05 AC 95 ms
52,164 KB
testcase_06 AC 109 ms
53,024 KB
testcase_07 AC 128 ms
53,360 KB
testcase_08 AC 139 ms
53,348 KB
testcase_09 AC 119 ms
52,412 KB
testcase_10 AC 113 ms
52,872 KB
testcase_11 AC 91 ms
52,132 KB
testcase_12 AC 112 ms
52,452 KB
testcase_13 AC 92 ms
52,216 KB
testcase_14 AC 98 ms
52,508 KB
testcase_15 AC 98 ms
51,484 KB
testcase_16 AC 84 ms
52,148 KB
testcase_17 AC 110 ms
53,000 KB
testcase_18 AC 106 ms
52,092 KB
testcase_19 AC 85 ms
51,760 KB
testcase_20 AC 107 ms
52,552 KB
testcase_21 AC 90 ms
52,312 KB
testcase_22 AC 87 ms
50,540 KB
testcase_23 AC 90 ms
51,572 KB
testcase_24 AC 81 ms
50,652 KB
testcase_25 AC 86 ms
50,316 KB
testcase_26 AC 74 ms
51,428 KB
testcase_27 AC 86 ms
51,576 KB
testcase_28 AC 85 ms
51,380 KB
testcase_29 AC 78 ms
51,624 KB
testcase_30 AC 44 ms
49,412 KB
testcase_31 AC 45 ms
49,316 KB
testcase_32 AC 45 ms
49,268 KB
testcase_33 AC 43 ms
49,316 KB
testcase_34 AC 44 ms
49,320 KB
権限があれば一括ダウンロードができます

ソースコード

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