結果

問題 No.2042 RGB Caps
ユーザー ks2mks2m
提出日時 2022-08-19 21:48:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 348 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 79,412 KB
実行使用メモリ 58,820 KB
最終ジャッジ日時 2024-04-27 20:32:31
合計ジャッジ時間 5,834 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
50,152 KB
testcase_01 AC 48 ms
50,236 KB
testcase_02 AC 47 ms
50,296 KB
testcase_03 AC 48 ms
50,216 KB
testcase_04 AC 49 ms
49,992 KB
testcase_05 AC 51 ms
49,980 KB
testcase_06 AC 139 ms
55,724 KB
testcase_07 AC 212 ms
56,064 KB
testcase_08 AC 262 ms
58,408 KB
testcase_09 AC 161 ms
55,488 KB
testcase_10 AC 299 ms
58,200 KB
testcase_11 AC 173 ms
56,280 KB
testcase_12 AC 347 ms
58,116 KB
testcase_13 AC 325 ms
58,820 KB
testcase_14 AC 348 ms
58,496 KB
testcase_15 AC 52 ms
50,248 KB
testcase_16 AC 214 ms
55,860 KB
testcase_17 AC 158 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		char[] s = new char[n];
		for (int i = 0; i < k; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			char c = sa[1].charAt(0);
			s[a] = c;
		}
		br.close();

		StringBuilder sb = new StringBuilder();
		label:
		for (int i = 0; i < n; i += 3) {
			TreeSet<Character> set = new TreeSet<>();
			set.add('R');
			set.add('G');
			set.add('B');
			for (int j = 0; j < 3; j++) {
				int idx = i + j;
				if (idx >= n) {
					break label;
				}
				if (s[idx] == '\u0000') {
					sb.append(set.pollFirst());
				} else {
					if (set.contains(s[idx])) {
						sb.append(s[idx]);
						set.remove(s[idx]);
					} else {
						sb.append(set.pollFirst());
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
}
0