結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー pengin_2000
提出日時 2025-11-01 16:40:08
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 27,728 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-01 16:40:26
合計ジャッジ時間 1,832 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d %d", &n, &m);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:12:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 scanf("%s", ss);
      |                 ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
char s[100005], ss[100005];
int id[100005], len;
char ans[100003];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j, k;
	for (i = 0; i < n; i++)
	{
		scanf("%s", ss);
		for (j = 0; j < m; j++)
			s[m * i + j] = ss[j];
	}
	for (i = 0; i < n; i++)
		id[i] = i;
	len = n;
	for (i = 0; i < m; i++)
		ans[i] = '?';
	ans[m] = '\0';
	int cnt[4];
	char q[4] = "GCP";
	for (j = 0; j < m; j++)
	{
		cnt[0] = cnt[1] = cnt[2] = 0;
		for (i = 0; i < len; i++)
		{
			if (s[m * id[i] + j] == 'G')
				cnt[0]++;
			else if (s[m * id[i] + j] == 'C')
				cnt[1]++;
			else
				cnt[2]++;
		}
		if (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0)
		{
			printf("-1\n");
			return 0;
		}
		cnt[3] = cnt[0];
		for (i = 0; i < 3; i++)
		{
			if (cnt[i] > 0 && cnt[i + 1] > 0)
			{
				ans[j] = q[i];
				k = 0;
				for (i = 0; i < len; i++)
					if (s[m * id[i] + j] == ans[j])
						id[k++] = id[i];
				len = k;
				break;
			}
		}
		if (ans[j] != '?')
			continue;
		for (i = 0; i < 3; i++)
			if (cnt[i] > 0)
				ans[j] = q[(i + 2) % 3];
		for (j++; j < m; j++)
			ans[j] = 'G';
		printf("%s\n", ans);
		return 0;
	}
	printf("-1\n");
	return 0;
}
0