結果

問題 No.2042 RGB Caps
ユーザー 👑 ygussanyygussany
提出日時 2022-08-20 13:32:30
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,778 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 32,128 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 12:28:04
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 9 ms
5,376 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 28 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 30 ms
5,376 KB
testcase_13 AC 32 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(int n, data x[])
{
	static data y[100001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}


int main()
{
	int i, N, K, A[100001];
	char c[100001];
	scanf("%d %d", &N, &K);
	for (i = 1; i <= K; i++) scanf("%d %c ", &(A[i]), &(c[i]));
	// for (i = 1; i <= K; i++) printf("%d %c\n", A[i], c[i]);
	
	data d[100001];
	for (i = 1; i <= K; i++) {
		d[i-1].key = A[i];
		d[i-1].id = i;
	}
	merge_sort(K, d);
	
	int j, count[3] = {};
	char ans[100001];
	for (i = 0, j = 1; i < K; i++) {
		for (; j <= d[i].key; j++) {
			if (c[d[i].id] == 'R' && count[0] <= count[1] && count[0] <= count[2]) {
				count[0]++;
				ans[j-1] = 'R';
			} else if (c[d[i].id] == 'G' && count[1] <= count[0] && count[1] <= count[2]) {
				count[1]++;
				ans[j-1] = 'G';
			} else if (c[d[i].id] == 'B' && count[2] <= count[0] && count[2] <= count[1]) {
				count[2]++;
				ans[j-1] = 'B';
			} else if (count[0] < count[1] || count[0] < count[2]) {
				count[0]++;
				ans[j-1] = 'R';
			} else if (count[1] < count[0] || count[1] < count[2]) {
				count[1]++;
				ans[j-1] = 'G';
			} else if (count[2] < count[0] || count[2] < count[1]) {
				count[2]++;
				ans[j-1] = 'B';
			} else {
				if (c[d[i].id] == 'R') {
					count[0]++;
					ans[j-1] = 'R';
				} else if (c[d[i].id] == 'G') {
					count[1]++;
					ans[j-1] = 'G';
				} else {
					count[2]++;
					ans[j-1] = 'B';
				}
			}
		}
	}
	ans[N] = 0;
	printf("%s\n", ans);
	fflush(stdout);
	return 0;
}
0