結果
| 問題 | No.2372 既視感 | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2023-07-11 14:01:54 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 132 ms / 2,000 ms | 
| コード長 | 3,528 bytes | 
| コンパイル時間 | 2,663 ms | 
| コンパイル使用メモリ | 96,580 KB | 
| 実行使用メモリ | 52,720 KB | 
| 最終ジャッジ日時 | 2024-09-13 04:27:15 | 
| 合計ジャッジ時間 | 6,172 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 | 
ソースコード
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();
    }
    
}
            
            
            
        