結果

問題 No.731 等差数列がだいすき
ユーザー YamaKasaYamaKasa
提出日時 2018-09-07 23:58:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 1,500 ms
コード長 1,189 bytes
コンパイル時間 3,215 ms
コンパイル使用メモリ 81,620 KB
実行使用メモリ 61,152 KB
最終ジャッジ日時 2023-08-20 02:17:15
合計ジャッジ時間 8,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
56,516 KB
testcase_01 AC 161 ms
56,900 KB
testcase_02 AC 161 ms
57,100 KB
testcase_03 AC 176 ms
57,308 KB
testcase_04 AC 218 ms
58,336 KB
testcase_05 AC 179 ms
57,068 KB
testcase_06 AC 238 ms
60,976 KB
testcase_07 AC 204 ms
57,180 KB
testcase_08 AC 230 ms
58,724 KB
testcase_09 AC 219 ms
58,620 KB
testcase_10 AC 232 ms
57,932 KB
testcase_11 AC 166 ms
57,312 KB
testcase_12 AC 194 ms
57,488 KB
testcase_13 AC 218 ms
58,296 KB
testcase_14 AC 213 ms
57,388 KB
testcase_15 AC 227 ms
58,948 KB
testcase_16 AC 184 ms
57,248 KB
testcase_17 AC 219 ms
60,156 KB
testcase_18 AC 228 ms
59,596 KB
testcase_19 AC 238 ms
61,152 KB
testcase_20 AC 232 ms
60,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double N = scan.nextInt();
		double[]a = new double[(int)N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextLong();
		}
		scan.close();
		double sum1 = 0;
		double sum2 = 0;
		for(int i = 0; i < N - 1; i++) {
			sum1 += a[0] - a[i + 1];
			sum2 += (i + 1)  * (a[0] - a[i + 1]);
		}
		double A = 2 * N;
		double B = N * (N - 1);
		double p = -2 * sum1;
		double C = 3 * N * (N - 1);
		double D = N * (N - 1) * (2 * N - 1);
		double q = -6 * sum2;
		double t = A * D - B * C;
		double x = (p * D - B * q) / t;
		double y = (A * q - p * C) / t;
//		System.out.println(A + " " + B + " " + C + " " + D);
//		System.out.println(p + " " + q);
		double b1 = a[0] + x;
		double cost = 0;
		for(int i = 0; i < N; i++) {
			double k = a[0] + x + i * y - a[i];
			k *= k;
			//BigDecimal bd = new BigDecimal(k);
			//BigDecimal bd2 = bd.setScale(10, BigDecimal.ROUND_HALF_UP);
			//double d = Double.parseDouble(bd2.toString());
			//System.out.println(d);
			cost += k;
		}
		System.out.println(b1 + " " + y);
		System.out.println(String.format("%.8f", cost));
	}
}
0