結果

問題 No.53 悪の漸化式
ユーザー ぴろずぴろず
提出日時 2014-12-15 12:52:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 908 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 73,612 KB
実行使用メモリ 56,284 KB
最終ジャッジ日時 2023-09-02 14:50:43
合計ジャッジ時間 5,557 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,988 KB
testcase_01 AC 126 ms
55,824 KB
testcase_02 AC 122 ms
55,976 KB
testcase_03 AC 121 ms
55,620 KB
testcase_04 AC 120 ms
54,204 KB
testcase_05 AC 122 ms
55,856 KB
testcase_06 AC 123 ms
56,064 KB
testcase_07 AC 124 ms
55,836 KB
testcase_08 AC 125 ms
56,112 KB
testcase_09 AC 125 ms
55,760 KB
testcase_10 AC 124 ms
56,180 KB
testcase_11 AC 125 ms
55,852 KB
testcase_12 AC 128 ms
55,884 KB
testcase_13 AC 129 ms
55,860 KB
testcase_14 AC 130 ms
56,040 KB
testcase_15 AC 131 ms
56,256 KB
testcase_16 AC 128 ms
56,284 KB
testcase_17 AC 131 ms
56,028 KB
testcase_18 AC 134 ms
55,884 KB
testcase_19 AC 135 ms
56,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no053;

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		BigDecimal x0 = new BigDecimal("4");
		BigDecimal x1 = new BigDecimal("3");
		BigDecimal c1 = new BigDecimal("19");
		BigDecimal c2 = new BigDecimal("-12");
		BigDecimal c3 = new BigDecimal("4");
		if (n <= 1) {
			if (n == 0) {
				System.out.println(x0);
			}else{
				System.out.println(x1);
			}
			return;
		}
		BigDecimal x2 = BigDecimal.ZERO;
		for(int i=0;i<n-1;i++) {
//			System.out.println(x2);
			x2 = x1.multiply(c1).add(x0.multiply(c2)).divide(c3);
			x0 = x1;
			x1 = x2;
		}
		if (x2.compareTo(new BigDecimal("1E-9")) <= 0) {
			System.out.println(0);
		}else{
			System.out.println(x2.setScale(10,BigDecimal.ROUND_HALF_EVEN).toPlainString());
		}
	}

}
0