結果

問題 No.161 制限ジャンケン
ユーザー rodearodea
提出日時 2017-11-09 21:43:31
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 974 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 29,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 05:12:24
合計ジャッジ時間 990 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>

int main(void)
{
	int g, g1 = 0, c, c1 = 0, p, p1 = 0, ng = 0, ng1 = 0, ng2 = 0, nc = 0, nc1 = 0, nc2 = 0, np = 0, np1 = 0, np2 = 0, ans1, ans2;

	scanf("%d %d %d", &g, &c, &p);

	int n = g + c + p;

	char s[300];

	for (int i = 0; i < n+1; i++)
	{
		s[i] = getchar();

		if (s[i] == 'G') ng++;

		else if (s[i] == 'C') nc++;

		else if (s[i] == 'P') np++;
	}

	if (g >= nc)
	{
		g = g - nc;
		nc1 = nc;
		nc = 0;
	}

	else
	{
		nc = nc - g;
		nc2 = g;
		g = 0;
	}

	if (c >= np)
	{
		c = c - np;
		np1 = np;
		np = 0;
	}

	else
	{
		np = np - c;
		np2 = c;
		c = 0;
	}

	if (p >= ng)
	{
		p = p - ng;
		ng1 = ng;
		ng = 0;
	}

	else
	{
		ng = ng - p;
		ng2 = p;
		p = 0;
	}

	ans1 = (ng1 + nc1 + np1 + ng2 + nc2 + np2) * 3;

	if (g > 0 && ng > 0)
	{
		 g1 = g > ng ? ng : g;
	}

	if (c > 0 && nc > 0)
	{
		 c1 = c > nc ? nc : c;
	}

	if (p > 0 && np > 0)
	{
		 p1 = p > np ? np : p;
	}

	ans2 = g1 + c1 + p1;

	printf("%d\n", ans1 + ans2);

	return 0;

}
0