結果

問題 No.714 回転寿司屋のシミュレート
ユーザー tentententen
提出日時 2020-10-14 13:31:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 2,657 ms
コンパイル使用メモリ 75,948 KB
実行使用メモリ 60,120 KB
最終ジャッジ日時 2023-09-28 00:35:51
合計ジャッジ時間 12,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
56,008 KB
testcase_01 AC 137 ms
56,032 KB
testcase_02 AC 167 ms
55,380 KB
testcase_03 AC 200 ms
57,404 KB
testcase_04 AC 200 ms
56,908 KB
testcase_05 AC 214 ms
60,120 KB
testcase_06 AC 231 ms
59,628 KB
testcase_07 AC 246 ms
57,976 KB
testcase_08 AC 274 ms
59,980 KB
testcase_09 AC 238 ms
59,640 KB
testcase_10 AC 238 ms
59,280 KB
testcase_11 AC 209 ms
59,644 KB
testcase_12 AC 223 ms
59,384 KB
testcase_13 AC 223 ms
59,248 KB
testcase_14 AC 223 ms
59,592 KB
testcase_15 AC 218 ms
58,956 KB
testcase_16 AC 217 ms
59,032 KB
testcase_17 AC 226 ms
59,868 KB
testcase_18 AC 219 ms
59,476 KB
testcase_19 AC 215 ms
59,700 KB
testcase_20 AC 217 ms
59,284 KB
testcase_21 AC 216 ms
59,452 KB
testcase_22 AC 212 ms
59,520 KB
testcase_23 AC 217 ms
59,212 KB
testcase_24 AC 214 ms
58,988 KB
testcase_25 AC 213 ms
59,368 KB
testcase_26 AC 215 ms
59,400 KB
testcase_27 AC 216 ms
59,220 KB
testcase_28 AC 211 ms
59,060 KB
testcase_29 AC 210 ms
59,188 KB
testcase_30 AC 133 ms
55,728 KB
testcase_31 AC 145 ms
56,172 KB
testcase_32 AC 141 ms
55,740 KB
testcase_33 AC 131 ms
56,172 KB
testcase_34 AC 135 ms
55,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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