結果
問題 |
No.126 2基のエレベータ
|
ユーザー |
|
提出日時 | 2020-03-22 02:31:58 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 130 ms / 5,000 ms |
コード長 | 889 bytes |
コンパイル時間 | 2,021 ms |
コンパイル使用メモリ | 77,660 KB |
実行使用メモリ | 41,524 KB |
最終ジャッジ日時 | 2024-10-10 18:36:31 |
合計ジャッジ時間 | 6,720 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { long t = System.currentTimeMillis(); new Main().run(); System.err.println(System.currentTimeMillis() - t); } void run() { Scanner sc = new Scanner(System.in); int A=sc.nextInt(); int B=sc.nextInt(); int S=sc.nextInt(); int ans=Integer.MAX_VALUE/3; if(S==1) { ans=Math.abs(A-S)+1; }else if(Math.abs(S-A)<=Math.abs(S-B)) { ans=Math.abs(S-A)+Math.abs(S-0); }else { if(A>0) { ans=Math.abs(S-B)+Math.abs(A-S)+Math.abs(A); }else { ans=Math.abs(S-B)+Math.abs(S-1)+2; } } ans=Math.min(ans, Math.abs(S-B)+Math.abs(S-1)+Math.abs(A-1)+1); System.out.println(ans); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }