結果

問題 No.91 赤、緑、青の石
コンテスト
ユーザー rieaaddlreiuu
提出日時 2022-11-03 22:02:08
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 767 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,102 ms
コンパイル使用メモリ 162,136 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-07 12:40:23
合計ジャッジ時間 2,091 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%d %d %d",&r,&g,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

bool can_create(int k,int r,int g,int b){
    r -= k;
    g -= k;
    b -= k;
    int plus = 0;
    int minus = 0;
    if(r > 0){
        plus += r/2;
    } else {
        minus -= r;
    }
    if(g > 0){
        plus += g/2;
    } else {
        minus -= g;
    }
    if(b > 0){
        plus += b/2;
    } else {
        minus -= b;
    }
    if(plus >= minus){
        return true;
    }
    return false;
}

int main(){
    int i,r,g,b;
    scanf("%d %d %d",&r,&g,&b);
    int left = 0,right = r+g+b;
    int mid;
    while(right - left >= 2){
        mid = (right + left)/2;
        if(can_create(mid,r,g,b)){
            left = mid;
        } else {
            right = mid;
        }
    }
    printf("%d",left);
}
0