結果

問題 No.2372 既視感
ユーザー tentententen
提出日時 2023-07-11 14:01:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 3,528 bytes
コンパイル時間 2,654 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 53,016 KB
最終ジャッジ日時 2023-10-11 05:09:04
合計ジャッジ時間 6,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
47,972 KB
testcase_01 AC 44 ms
49,392 KB
testcase_02 AC 43 ms
49,564 KB
testcase_03 AC 43 ms
49,380 KB
testcase_04 AC 43 ms
49,464 KB
testcase_05 AC 42 ms
49,384 KB
testcase_06 AC 42 ms
49,508 KB
testcase_07 AC 42 ms
49,384 KB
testcase_08 AC 83 ms
50,436 KB
testcase_09 AC 64 ms
50,728 KB
testcase_10 AC 84 ms
51,764 KB
testcase_11 AC 77 ms
51,680 KB
testcase_12 AC 47 ms
49,408 KB
testcase_13 AC 89 ms
52,008 KB
testcase_14 AC 51 ms
50,276 KB
testcase_15 AC 80 ms
50,988 KB
testcase_16 AC 69 ms
50,536 KB
testcase_17 AC 55 ms
50,536 KB
testcase_18 AC 51 ms
50,548 KB
testcase_19 AC 48 ms
49,436 KB
testcase_20 AC 48 ms
49,864 KB
testcase_21 AC 47 ms
49,540 KB
testcase_22 AC 56 ms
50,528 KB
testcase_23 AC 102 ms
53,016 KB
testcase_24 AC 86 ms
51,764 KB
testcase_25 AC 102 ms
52,292 KB
testcase_26 AC 103 ms
52,388 KB
testcase_27 AC 104 ms
52,632 KB
testcase_28 AC 123 ms
52,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        HashMap<String, Integer> counts = new HashMap<>();
        ArrayDeque<String> deq = new ArrayDeque<>();
        while (q-- > 0) {
            if (sc.nextInt() == 1) {
                String title = sc.next();
                counts.put(title, counts.getOrDefault(title, 0) + 1);
                deq.add(title);
                if (deq.size() > n) {
                    String x = deq.poll();
                    if (counts.get(x) == 1) {
                        counts.remove(x);
                    } else {
                        counts.put(x, counts.get(x) - 1);
                    }
                }
            } else {
                String[] titles = new String[6];
                int[] times = new int[6];
                for (int i = 0; i < 6; i++) {
                    titles[i] = sc.next();
                    times[i] = sc.nextInt();
                }
                int count = 0;
                int current = 0;
                for (int i = 0; i < 6; i++) {
                    int score = times[i];
                    if (counts.containsKey(titles[i])) {
                        score = Math.min(score, k);
                    }
                    if (score + current <= 60) {
                        current += score;
                        count++;
                    } else {
                        break;
                    }
                }
                sb.append(count).append("\n");
                for (int i = 0; i < count; i++) {
                    deq.add(titles[i]);
                    counts.put(titles[i], counts.getOrDefault(titles[i], 0) + 1);
                }
                while (deq.size() > n) {
                    String x = deq.poll();
                    if (counts.get(x) == 1) {
                        counts.remove(x);
                    } else {
                        counts.put(x, counts.get(x) - 1);
                    }
                }
            }
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0