結果
問題 |
No.731 等差数列がだいすき
|
ユーザー |
![]() |
提出日時 | 2019-09-14 10:19:32 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 186 ms / 1,500 ms |
コード長 | 775 bytes |
コンパイル時間 | 1,962 ms |
コンパイル使用メモリ | 78,848 KB |
実行使用メモリ | 44,968 KB |
最終ジャッジ日時 | 2024-07-05 17:21:04 |
合計ジャッジ時間 | 6,452 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] a = new long[n]; for(int i = 0; i < n; i++) { a[i] = sc.nextLong(); } long xy = 0; long x = 0; long y = 0; long x2 = 0; for(int i = 0; i < n; i++) { xy += (i * a[i]); x += i; y += a[i]; x2 += (i * i); } double A = (double)(n * xy - x * y) / (double)(n * x2 - x * x); double B = (double)(x2 * y - xy * x) / (double)(n * x2 - x * x); double c = 0; for(int i = 0; i < n; i++) { double t = A * (double)i + B; c += ((double)((a[i] - t) * (a[i] - t))); } System.out.println(B + " " + A); System.out.println(c); } }