結果

問題 No.333 門松列を数え上げ
ユーザー ぴろずぴろず
提出日時 2016-01-15 22:38:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 74,328 KB
実行使用メモリ 57,592 KB
最終ジャッジ日時 2023-10-19 23:14:36
合計ジャッジ時間 3,844 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,288 KB
testcase_01 AC 132 ms
57,128 KB
testcase_02 AC 133 ms
57,216 KB
testcase_03 AC 131 ms
57,156 KB
testcase_04 AC 131 ms
57,592 KB
testcase_05 AC 131 ms
57,224 KB
testcase_06 AC 132 ms
57,408 KB
testcase_07 AC 132 ms
57,416 KB
testcase_08 AC 133 ms
57,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no333;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long ans = 0;
		long min = Math.min(a, b);
		long max = Math.max(a, b);
		if (min > 1 && isKadomatsuSequence(a, b, 1)) {
			ans += Math.min(a, b) - 1;
		}
		if(min + 1 < max && isKadomatsuSequence(a, b, a+1)) {
			ans += max - min - 1;
		}
		if (max < 2000000000 && isKadomatsuSequence(a, b, 2000000000)) {
			ans += 2000000000 - max;
		}
		System.out.println(ans);
	}
	
	public static boolean isKadomatsuSequence(long a,long b,long c) {
		if (a == b || b == c) {
			return false;
		}
		return b < a && b < c || b > a && b > c;
	}

}
0