結果

問題 No.606 カラフルタイル
ユーザー tentententen
提出日時 2023-12-19 10:07:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 503 ms / 2,000 ms
コード長 2,622 bytes
コンパイル時間 2,893 ms
コンパイル使用メモリ 92,680 KB
実行使用メモリ 72,056 KB
最終ジャッジ日時 2023-12-19 10:07:53
合計ジャッジ時間 11,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
54,760 KB
testcase_01 AC 69 ms
54,644 KB
testcase_02 AC 70 ms
54,768 KB
testcase_03 AC 69 ms
54,636 KB
testcase_04 AC 71 ms
54,760 KB
testcase_05 AC 70 ms
54,880 KB
testcase_06 AC 72 ms
54,740 KB
testcase_07 AC 70 ms
54,756 KB
testcase_08 AC 72 ms
54,876 KB
testcase_09 AC 69 ms
54,756 KB
testcase_10 AC 69 ms
54,768 KB
testcase_11 AC 70 ms
54,888 KB
testcase_12 AC 82 ms
54,868 KB
testcase_13 AC 175 ms
60,944 KB
testcase_14 AC 72 ms
54,740 KB
testcase_15 AC 106 ms
55,504 KB
testcase_16 AC 318 ms
62,420 KB
testcase_17 AC 459 ms
71,848 KB
testcase_18 AC 384 ms
67,020 KB
testcase_19 AC 364 ms
67,028 KB
testcase_20 AC 503 ms
72,056 KB
testcase_21 AC 388 ms
67,164 KB
testcase_22 AC 393 ms
66,848 KB
testcase_23 AC 415 ms
67,076 KB
testcase_24 AC 452 ms
68,776 KB
testcase_25 AC 388 ms
66,456 KB
testcase_26 AC 459 ms
71,288 KB
testcase_27 AC 474 ms
71,956 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();
        boolean[] isRow = new boolean[q];
        int[] idxes = new int[q];
        int[] colors = new int[q];
        for (int i = 0; i < q; i++) {
            isRow[i] = (sc.next().charAt(0) == 'R');
            idxes[i] = sc.nextInt();
            colors[i] = sc.nextInt() - 1;
        }
        long[] ans = new long[k];
        ans[0] = (long)n * n;
        HashSet<Integer> rows = new HashSet<>();
        HashSet<Integer> cols = new HashSet<>();
        for (int i = q - 1; i >= 0; i--) {
            int value;
            if (isRow[i]) {
                if (rows.contains(idxes[i])) {
                    continue;
                }
                rows.add(idxes[i]);
                value = n - cols.size();
            } else {
                if (cols.contains(idxes[i])) {
                    continue;
                }
                cols.add(idxes[i]);
                value = n - rows.size();
            }
            ans[colors[i]] += value;
            ans[0] -= value;
        }
        System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new)));
    }
}
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