結果

問題 No.91 赤、緑、青の石
コンテスト
ユーザー bal4u
提出日時 2019-06-22 18:35:32
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 777 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 171 ms
コンパイル使用メモリ 39,392 KB
最終ジャッジ日時 2026-02-22 03:39:32
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: No.91 赤、緑、青の石
// 2019.6.22 bal4u

#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) { return *(int *)b - *(int *)a; }

int bsch(int A, int B)
{
	int a, b, l = 0, r = B;

    while (l+1 < r) {
        b = (l + r) >> 1;
		a = (B - b) / 3;
		if (a + 3*b > A) r = b;
		else l = b;
    }
	return l
	;
}

int main()
{
	int i, A[3], ans;

	for (i = 0; i < 3; i++) scanf("%d", A+i);
	qsort(A, 3, sizeof(int), cmp);
	ans = A[2], A[0] -= ans, A[1] -= ans;
	
	if (A[1] > 0) {
		if (A[0] >= 3*A[1]) ans += A[1], A[0] -= A[1]*3, A[1] = 0;
		else if (A[0] >= 3) {
			int a, b;
			b = bsch(A[0], A[1]);
			a = (A[1] - b)/3;
			ans += a + b;
			A[0] -= a + 3*b, A[1] -= 3*a + b;
		}
	}

	ans += A[0]/5;
	printf("%d\n", ans);
	return 0;
}
0