結果
| 問題 | 
                            No.126 2基のエレベータ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             YamaKasa
                         | 
                    
| 提出日時 | 2018-07-14 15:57:44 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 139 ms / 5,000 ms | 
| コード長 | 707 bytes | 
| コンパイル時間 | 2,097 ms | 
| コンパイル使用メモリ | 74,888 KB | 
| 実行使用メモリ | 54,280 KB | 
| 最終ジャッジ日時 | 2024-10-10 18:33:12 | 
| 合計ジャッジ時間 | 7,107 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int S = scan.nextInt();
		scan.close();
		int l1 = Math.abs(S - A);
		int l2 = Math.abs(S - B);
		if(S == 1) {
			if(A == 0) {
				System.out.println(2);
			}else {
				System.out.println(A);
			}
			System.exit(0);
		}
		if(l1 <= l2) {
			int ans = l1 + S;
			System.out.println(ans);
		}else {
			int ans = l2;
			if(A == 0) {
				ans += 2 + S - 1;
				System.out.println(ans);
				System.exit(0);
			}
			int t1 = l1 + A;
			int t2 = S + Math.abs(A - 1);
			ans += Math.min(t1, t2);
			System.out.println(ans);
		}
	}
}
            
            
            
        
            
YamaKasa