結果

問題 No.1884 Sequence
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-21 00:11:34
言語 C#
(.NET 8.0.203)
結果
RE  
実行時間 -
コード長 1,461 bytes
コンパイル時間 6,700 ms
コンパイル使用メモリ 158,612 KB
実行使用メモリ 208,080 KB
最終ジャッジ日時 2023-11-21 00:11:55
合計ジャッジ時間 20,021 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
33,060 KB
testcase_01 AC 80 ms
33,188 KB
testcase_02 AC 80 ms
33,060 KB
testcase_03 AC 75 ms
32,676 KB
testcase_04 RE -
testcase_05 AC 81 ms
33,060 KB
testcase_06 AC 80 ms
33,060 KB
testcase_07 AC 80 ms
33,188 KB
testcase_08 AC 79 ms
33,188 KB
testcase_09 AC 81 ms
33,060 KB
testcase_10 AC 482 ms
65,788 KB
testcase_11 AC 481 ms
65,788 KB
testcase_12 AC 105 ms
45,096 KB
testcase_13 AC 107 ms
45,936 KB
testcase_14 AC 110 ms
45,152 KB
testcase_15 AC 310 ms
53,868 KB
testcase_16 AC 486 ms
65,756 KB
testcase_17 AC 189 ms
49,808 KB
testcase_18 AC 373 ms
55,020 KB
testcase_19 AC 226 ms
51,448 KB
testcase_20 AC 258 ms
52,056 KB
testcase_21 AC 202 ms
48,676 KB
testcase_22 AC 282 ms
53,016 KB
testcase_23 AC 486 ms
65,768 KB
testcase_24 AC 486 ms
65,756 KB
testcase_25 AC 504 ms
64,672 KB
testcase_26 AC 483 ms
65,680 KB
testcase_27 AC 105 ms
46,836 KB
testcase_28 RE -
testcase_29 AC 110 ms
47,216 KB
testcase_30 AC 109 ms
47,216 KB
testcase_31 AC 265 ms
50,952 KB
testcase_32 AC 461 ms
64,484 KB
testcase_33 AC 358 ms
65,864 KB
testcase_34 AC 357 ms
65,864 KB
testcase_35 AC 133 ms
48,624 KB
testcase_36 AC 266 ms
56,508 KB
testcase_37 AC 359 ms
65,864 KB
testcase_38 AC 355 ms
62,748 KB
testcase_39 AC 166 ms
48,292 KB
testcase_40 AC 175 ms
49,040 KB
testcase_41 AC 397 ms
60,644 KB
testcase_42 AC 399 ms
208,080 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (91 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
        // Test();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        WriteLine(Card(n, a) ? "Yes" : "No");
    }
    static bool Card(int n, long[] a)
    {
        if (n == 2) return true;
        var nonzero = a.Where(ai => ai != 0).ToList();
        if (nonzero.Count == 0)
        {
            return true;
        }
        nonzero.Sort();
        var dlist = new List<long>();
        for (var i = 0; i + 1 < nonzero.Count; ++i) dlist.Add(nonzero[i + 1] - nonzero[i]);
        if (dlist.Any(d => d == 0))
        {
            return nonzero[0] == nonzero[^1];
        }
        var gcd = dlist[0];
        for (var i = 1; i < dlist.Count; ++i) gcd = GCD(gcd, dlist[i]);
        var zerocount = (long)n - nonzero.Count;
        foreach (var d in dlist)
        {
            zerocount -= d / gcd - 1;
            if (zerocount < 0)
            {
                return false;
            }
        }
        return true;
    }
    static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
}
0