結果
問題 | No.731 等差数列がだいすき |
ユーザー |
![]() |
提出日時 | 2016-07-07 13:26:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 35 ms / 1,500 ms |
コード長 | 1,739 bytes |
コンパイル時間 | 1,783 ms |
コンパイル使用メモリ | 107,520 KB |
実行使用メモリ | 20,608 KB |
最終ジャッジ日時 | 2024-10-12 23:01:47 |
合計ジャッジ時間 | 2,364 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; class Program { static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); long n = sc.Int; var a = sc.LongArr; if (n == 2) { sw.WriteLine("{0} {1}", a[0], a[1] - a[0]); sw.WriteLine(0); sw.Flush(); return; } long n1 = n * (n - 1) / 2; long n2 = n * (n - 1) * (n * 2 - 1) / 6; long asum = 0, asum2 = 0; for (int i = 0; i < n; i++) { asum += a[i]; asum2 += a[i] * i; } double b = (n2 * asum - n1 * asum2) / (double)(n * n2 - n1 * n1); double d = (n * asum2 - n1 * asum) / (double)(n * n2 - n1 * n1); double c = 0; for (int i = 0; i < n; i++) { c += pow(b + i * d - a[i]); } sw.WriteLine("{0} {1}", b, d); sw.WriteLine(c); sw.Flush(); } static double pow(double a) { return a * a; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public int[] IntArrWithSep(char sep) { return Str.Split(sep).Select(int.Parse).ToArray(); } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } }