結果

問題 No.731 等差数列がだいすき
ユーザー りあんりあん
提出日時 2016-07-07 13:26:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 1,500 ms
コード長 1,739 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 106,496 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-04-21 00:41:44
合計ジャッジ時間 3,179 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
19,712 KB
testcase_01 AC 27 ms
19,840 KB
testcase_02 AC 27 ms
19,840 KB
testcase_03 AC 30 ms
20,352 KB
testcase_04 AC 30 ms
20,352 KB
testcase_05 AC 31 ms
20,096 KB
testcase_06 AC 31 ms
20,352 KB
testcase_07 AC 31 ms
20,480 KB
testcase_08 AC 30 ms
20,096 KB
testcase_09 AC 33 ms
20,352 KB
testcase_10 AC 30 ms
20,480 KB
testcase_11 AC 25 ms
19,712 KB
testcase_12 AC 29 ms
20,224 KB
testcase_13 AC 30 ms
20,224 KB
testcase_14 AC 30 ms
20,096 KB
testcase_15 AC 29 ms
20,224 KB
testcase_16 AC 31 ms
20,224 KB
testcase_17 AC 29 ms
20,480 KB
testcase_18 AC 31 ms
20,224 KB
testcase_19 AC 32 ms
20,352 KB
testcase_20 AC 30 ms
20,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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(); } }
}
0