結果

問題 No.1884 Sequence
ユーザー bluemeganebluemegane
提出日時 2022-03-26 07:52:18
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 3,042 ms
コンパイル使用メモリ 105,728 KB
実行使用メモリ 49,408 KB
最終ジャッジ日時 2024-04-22 18:09:41
合計ジャッジ時間 7,847 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,048 KB
testcase_01 AC 28 ms
18,176 KB
testcase_02 AC 29 ms
18,176 KB
testcase_03 AC 26 ms
17,920 KB
testcase_04 AC 26 ms
17,920 KB
testcase_05 AC 26 ms
17,792 KB
testcase_06 AC 28 ms
18,176 KB
testcase_07 AC 28 ms
17,920 KB
testcase_08 AC 28 ms
17,920 KB
testcase_09 AC 29 ms
18,304 KB
testcase_10 AC 199 ms
49,104 KB
testcase_11 AC 198 ms
49,280 KB
testcase_12 AC 64 ms
25,728 KB
testcase_13 AC 76 ms
30,848 KB
testcase_14 AC 65 ms
25,984 KB
testcase_15 AC 146 ms
42,240 KB
testcase_16 AC 199 ms
49,024 KB
testcase_17 AC 105 ms
36,480 KB
testcase_18 AC 143 ms
41,600 KB
testcase_19 AC 117 ms
40,192 KB
testcase_20 AC 134 ms
41,088 KB
testcase_21 AC 108 ms
35,584 KB
testcase_22 AC 141 ms
41,344 KB
testcase_23 AC 200 ms
48,960 KB
testcase_24 AC 199 ms
49,024 KB
testcase_25 AC 199 ms
48,476 KB
testcase_26 AC 202 ms
48,904 KB
testcase_27 AC 78 ms
31,104 KB
testcase_28 AC 78 ms
31,104 KB
testcase_29 AC 77 ms
30,976 KB
testcase_30 AC 80 ms
31,104 KB
testcase_31 AC 118 ms
37,632 KB
testcase_32 AC 193 ms
48,128 KB
testcase_33 AC 167 ms
49,408 KB
testcase_34 AC 164 ms
49,152 KB
testcase_35 AC 86 ms
32,128 KB
testcase_36 AC 138 ms
43,008 KB
testcase_37 AC 168 ms
49,280 KB
testcase_38 AC 160 ms
45,952 KB
testcase_39 AC 97 ms
34,560 KB
testcase_40 AC 100 ms
34,944 KB
testcase_41 AC 175 ms
45,208 KB
testcase_42 AC 174 ms
45,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = new List<long>();
        var z = 0;
        for (int i = 0; i < n; i++)
        {
            var t = long.Parse(line[i]);
            if (t == 0) z++;
            else a.Add(t);
        }
        getAns(n, z, a);
    }
    static bool checkD0(List<long> a)
    {
        var pre = a[0];
        foreach (var x in a)
            if (x != pre) return false;
        return true;
    }
    static void getAns(int n, int z, List<long> a)
    {
        var acount = a.Count;
        if (acount <=2) { Console.WriteLine("Yes");return; }
        a.Sort();
        var dlist = new List<long>();
        var g = a[1] - a[0];
        if (g == 0) { Console.WriteLine(checkD0(a) ? "Yes" : "No"); return; }
        dlist.Add(g);
        for (int i = 2; i < acount; i++)
        {
            var tt = a[i] - a[i - 1];
            if (tt == 0) { Console.WriteLine(checkD0(a) ? "Yes" : "No"); return; }
            g = Gcd(g, tt);
            dlist.Add(tt);
        }
        var ans = 0L;
        foreach (var x in dlist) ans += x / g - 1;
        Console.WriteLine(z >= ans ? "Yes" : "No");
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}
0