結果
| 問題 |
No.606 カラフルタイル
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-12 13:59:54 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 340 ms / 2,000 ms |
| コード長 | 2,341 bytes |
| コンパイル時間 | 2,201 ms |
| コンパイル使用メモリ | 78,736 KB |
| 実行使用メモリ | 67,100 KB |
| 最終ジャッジ日時 | 2024-11-24 23:57:07 |
| 合計ジャッジ時間 | 8,724 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
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();
}
}
tenten