結果

問題 No.91 赤、緑、青の石
ユーザー koyumeishikoyumeishi
提出日時 2014-12-07 21:07:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 954 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 73,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 12:07:16
合計ジャッジ時間 1,879 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;



long long bs(long long R, long long G, long long B){
	// [lb, ub)
	long long lb = 0;
	long long ub = max(R, max(G,B) ) + 1;
	while(ub-lb > 1){
		long long med = (ub+lb)/2;
		
		vector<long long> color(3);
		color[0] = R-med;
		color[1] = G-med;
		color[2] = B-med;

		for(int i=0; i<3; i++){
			for(int j=1; j<=2; j++){
				
				if(color[i] < 0){
					if(color[(i+j)%3] > 0){
						long long x = min( abs(color[i]), color[(i+j)%3]/2);
						color[i] += x;
						color[(i+j)%3] -= x*2;
					}
				}
				
			}
		}

		if(color[0] < 0 || color[1] < 0 || color[2] < 0){
			ub = med;
		}else{
			lb = med;
		}
	}
	return lb;
}

int main(){
	int R,G,B;
	cin >> R >> G >> B;
	cout << bs(R,G,B) << endl;

	
	return 0;
}
0