結果

問題 No.91 赤、緑、青の石
ユーザー HiroakiSoftware
提出日時 2014-12-07 23:11:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 844 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 23,424 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 06:45:41
合計ジャッジ時間 1,555 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%u %u %u", &r, &g, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/*
yukicoder No.91 赤、緑、青の石
解答者:ヒロソフ
*/
#include <stdio.h>

int main(void) {

	unsigned int r, g, b;
	unsigned int *p[2];
	int Count = 0;
	scanf("%u %u %u", &r, &g, &b);
	bool  bNext = false;
	do {
		bNext = false;
		while ((r > 0) && (g > 0) && (b > 0)) {
			//作れる間繰り返す
			Count++;
			r--;
			g--;
			b--;
		}
		//0のものを確認
		p[0] = nullptr;
		if (r == 0) p[0] = &r;
		else if (g == 0) p[0] = &g;
		else if (b == 0) p[0] = &b;

		//3つ以上あるもので最大のものを確認
		p[1] = &r;
		if (*p[1] < g) p[1] = &g;
		if (*p[1] < b) p[1] = &b;
		if (*p[1] >= 3) {
			//交換条件がそろったので交換して次のループへ
			*p[1] -= 2;
			*p[0] += 1;
			bNext = true;
		}
	} while (bNext);

	printf("%d\n", Count);
	return 0;
}
0