結果

問題 No.606 カラフルタイル
ユーザー htensai
提出日時 2019-11-14 12:35:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,037 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 78,964 KB
実行使用メモリ 65,868 KB
最終ジャッジ日時 2024-09-21 21:23:06
合計ジャッジ時間 17,976 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		long[] colors = new long[k + 1];
		boolean[] isRs = new boolean[q];
		int[] idxes = new int[q];
		int[] patterns = new int[q];
		for (int i = 0;  i < q; i++) {
		    isRs[i] = sc.next().charAt(0) == 'R';
		    idxes[i] = sc.nextInt();
		    patterns[i] = sc.nextInt();
		}
		HashSet<Integer> rSet = new HashSet<>();
		HashSet<Integer> cSet = new HashSet<>();
		long total = 0;
		for (int i = q - 1; i >= 0; i--) {
		    if (isRs[i]) {
		        if (!rSet.contains(idxes[i])) {
		            colors[patterns[i]] += n - cSet.size();
		            total += n - cSet.size();
		            rSet.add(idxes[i]);
		        }
		    } else {
		        if (!cSet.contains(idxes[i])) {
		            colors[patterns[i]] += n - rSet.size();
		            total += n - rSet.size();
		            cSet.add(idxes[i]);
		        }
		    }
		}
		colors[1] += n * n - total;
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= k; i++) {
		    sb.append(colors[i]).append("\n");
		}
	    System.out.print(sb);
	}
}
0