結果

問題 No.731 等差数列がだいすき
ユーザー りあんりあん
提出日時 2016-07-07 13:26:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 80 ms / 1,500 ms
コード長 1,739 bytes
コンパイル時間 3,443 ms
コンパイル使用メモリ 104,380 KB
実行使用メモリ 26,116 KB
最終ジャッジ日時 2023-08-03 00:58:30
合計ジャッジ時間 6,353 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
24,008 KB
testcase_01 AC 70 ms
25,876 KB
testcase_02 AC 70 ms
23,932 KB
testcase_03 AC 77 ms
23,984 KB
testcase_04 AC 78 ms
24,104 KB
testcase_05 AC 77 ms
22,188 KB
testcase_06 AC 79 ms
24,184 KB
testcase_07 AC 78 ms
24,080 KB
testcase_08 AC 78 ms
24,104 KB
testcase_09 AC 78 ms
24,044 KB
testcase_10 AC 79 ms
23,964 KB
testcase_11 AC 71 ms
23,972 KB
testcase_12 AC 78 ms
26,108 KB
testcase_13 AC 78 ms
24,096 KB
testcase_14 AC 80 ms
24,216 KB
testcase_15 AC 79 ms
26,072 KB
testcase_16 AC 79 ms
24,108 KB
testcase_17 AC 78 ms
24,052 KB
testcase_18 AC 79 ms
23,992 KB
testcase_19 AC 79 ms
26,116 KB
testcase_20 AC 78 ms
24,064 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