結果

問題 No.358 も~っと!門松列
ユーザー rn4rurn4ru
提出日時 2016-04-17 22:59:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 1,000 ms
コード長 892 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 54,548 KB
最終ジャッジ日時 2024-04-15 02:24:02
合計ジャッジ時間 6,377 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
54,232 KB
testcase_01 AC 135 ms
53,936 KB
testcase_02 AC 133 ms
54,376 KB
testcase_03 AC 135 ms
53,972 KB
testcase_04 AC 141 ms
54,024 KB
testcase_05 AC 132 ms
54,272 KB
testcase_06 AC 131 ms
54,156 KB
testcase_07 AC 137 ms
54,292 KB
testcase_08 AC 134 ms
53,852 KB
testcase_09 AC 137 ms
54,080 KB
testcase_10 AC 142 ms
54,220 KB
testcase_11 AC 134 ms
54,548 KB
testcase_12 AC 135 ms
54,148 KB
testcase_13 AC 136 ms
54,208 KB
testcase_14 AC 136 ms
54,184 KB
testcase_15 AC 134 ms
53,904 KB
testcase_16 AC 135 ms
54,184 KB
testcase_17 AC 137 ms
54,348 KB
testcase_18 AC 134 ms
54,140 KB
testcase_19 AC 137 ms
54,264 KB
testcase_20 AC 139 ms
54,160 KB
testcase_21 AC 142 ms
54,268 KB
testcase_22 AC 138 ms
54,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A[] = new int[3];
		for (int i = 0; i < 3; i++) {
			A[i] = scanner.nextInt();
		}

		System.out.println(new Solver().solve(A));

	}

}

class Solver {

	public String solve(int[] a) {
		if (a[0] == a[1] || a[0] == a[2] || a[1] == a[2]) {
			return "0";
		}

		if (isKadomatsu(a[0], a[1], a[2])) {
			return "INF";
		}

		int sum = 0;
		int max = Math.max(Math.max(a[0], a[1]), a[2]);
		for (int i = 1; i <= max; i++) {
			int b1 = a[0] % i;
			int b2 = a[1] % i;
			int b3 = a[2] % i;
			if (isKadomatsu(b1, b2, b3)) {
				sum++;
			}
		}
		return String.valueOf(sum);
	}

	private boolean isKadomatsu(int b1, int b2, int b3) {
		if (b1 == b2 || b1 == b3 || b2 == b3) {
			return false;
		}
		return (b2 > b1 && b2 > b3) || (b2 < b1 && b2 < b3);
	}

}
0