結果
| 問題 | No.91 赤、緑、青の石 |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-06-22 18:35:32 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 777 bytes |
| 記録 | |
| コンパイル時間 | 226 ms |
| コンパイル使用メモリ | 27,468 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-07 12:33:36 |
| 合計ジャッジ時間 | 1,222 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:27:33: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | for (i = 0; i < 3; i++) scanf("%d", A+i);
| ^~~~~~~~~~~~~~~~
ソースコード
// 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;
}
bal4u