結果

問題 No.606 カラフルタイル
ユーザー tentententen
提出日時 2021-11-12 13:59:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 2,341 bytes
コンパイル時間 1,932 ms
コンパイル使用メモリ 78,552 KB
実行使用メモリ 57,524 KB
最終ジャッジ日時 2024-05-03 20:01:32
合計ジャッジ時間 8,463 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
37,020 KB
testcase_01 AC 47 ms
37,152 KB
testcase_02 AC 47 ms
37,156 KB
testcase_03 AC 48 ms
36,980 KB
testcase_04 AC 48 ms
37,084 KB
testcase_05 AC 49 ms
36,604 KB
testcase_06 AC 49 ms
36,608 KB
testcase_07 AC 48 ms
36,928 KB
testcase_08 AC 48 ms
37,076 KB
testcase_09 AC 49 ms
37,068 KB
testcase_10 AC 48 ms
37,080 KB
testcase_11 AC 49 ms
37,060 KB
testcase_12 AC 50 ms
37,176 KB
testcase_13 AC 134 ms
42,060 KB
testcase_14 AC 49 ms
36,724 KB
testcase_15 AC 83 ms
38,432 KB
testcase_16 AC 235 ms
46,584 KB
testcase_17 AC 329 ms
55,448 KB
testcase_18 AC 274 ms
50,428 KB
testcase_19 AC 275 ms
52,796 KB
testcase_20 AC 328 ms
52,016 KB
testcase_21 AC 289 ms
51,980 KB
testcase_22 AC 292 ms
50,508 KB
testcase_23 AC 303 ms
52,020 KB
testcase_24 AC 320 ms
52,324 KB
testcase_25 AC 303 ms
49,188 KB
testcase_26 AC 332 ms
57,524 KB
testcase_27 AC 366 ms
55,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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();
        long total = (long)n * n;
        boolean[] isRows = new boolean[q];
        int[] nums = new int[q];
        int[] colors = new int[q];
        for (int i = 0; i < q; i++) {
            isRows[i] = (sc.next().charAt(0) == 'R');
            nums[i] = sc.nextInt();
            colors[i] = sc.nextInt() - 1;
        }
        int rowCount = n;
        int colCount = n;
        HashSet<Integer> rowUsed = new HashSet<>();
        HashSet<Integer> colUsed = new HashSet<>();
        long[] counts = new long[k];
        for (int i = q - 1; i >= 0; i--) {
            if (isRows[i]) {
                if (rowUsed.contains(nums[i])) {
                    continue;
                }
                rowUsed.add(nums[i]);
                rowCount--;
                counts[colors[i]] += colCount;
                total -= colCount;
            } else {
                if (colUsed.contains(nums[i])) {
                    continue;
                }
                colUsed.add(nums[i]);
                colCount--;
                counts[colors[i]] += rowCount;
                total -= rowCount;
            }
        }
        counts[0] += total;
        StringBuilder sb = new StringBuilder();
        for (long x : counts) {
            sb.append(x).append("\n");
        }
        System.out.print(sb);
    }
}
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 nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0