結果

問題 No.91 赤、緑、青の石
ユーザー kohaku_kohaku
提出日時 2017-01-12 04:14:35
言語 Java
(openjdk 23)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 1,249 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 77,632 KB
実行使用メモリ 56,280 KB
最終ジャッジ日時 2024-06-24 07:02:43
合計ジャッジ時間 7,569 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int [] rgb = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
        Arrays.sort(rgb);
        int min=rgb[0];
        int A = rgb[1]-rgb[0];
        int B = rgb[2]-rgb[0];
        int ans = min + sim(A,B);
        System.out.println(ans);
    }
    static int sim(int A, int B){
        int r = 0;
        while(A>=3||B>=3){
            if(A>B){
                int tmp=A;
                A=B;
                B=tmp;
            }
            if(B-A>=2){
                int k = (B-A)/2;
                if(k<=A){
                    B=B-3*k;
                    A=A-k;
                    r=r+k;
                }else{
                    r=r+A;
                    B=B-(3*A);
                    A=0;
                }
            }
            if(B-A<=1){
                int k=A/4;
                r=r+k*2;
                A=A-k*4;
                B=B-k*4;
            }
            if(A==0){
                int k=B/5;
                r=r+k;
                break;
            }else if(B>=3){
                A=A-1;
                B=B-3;
                r++;
            }
        }
        return r;
    }
}
0