結果

問題 No.91 赤、緑、青の石
ユーザー r.suzuki
提出日時 2015-12-30 22:45:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 3,540 ms
コンパイル使用メモリ 77,880 KB
実行使用メモリ 54,432 KB
最終ジャッジ日時 2024-06-24 06:53:07
合計ジャッジ時間 9,395 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

class Stone {
	int count;
	static int jewelry;

	Stone(int i) {
		this.count = i;
	}

	static void makeJewelry(Stone r, Stone g, Stone b) {
		r.count--;
		g.count--;
		b.count--;
		jewelry++;
	}

	static boolean checkJewelry(Stone r, Stone g, Stone b) {
		if (r.count >= 1 && g.count >= 1 && b.count >= 1) {
			return true;
		} else {
			return false;
		}
	}

	static void adjust(Stone r, Stone g, Stone b) {
		Stone x = r.count > g.count ? r : g;
		Stone max = x.count > b.count ? x : b;
		Stone n = r.count < g.count ? r : g;
		Stone min = n.count < b.count ? n : b;
		max.count -= 2;
		min.count += 1;
	}
}

public class No_91 {

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		Stone red = new Stone(sc.nextInt());
		Stone green = new Stone(sc.nextInt());
		Stone blue = new Stone(sc.nextInt());

		while (red.count >= 0 && green.count >= 0 && blue.count >= 0) {
			if (Stone.checkJewelry(red, green, blue)) {
				Stone.makeJewelry(red, green, blue);
				;
			} else {
				Stone.adjust(red, green, blue);
			}
		}
		System.out.println(Stone.jewelry);

	}

}
0