結果

問題 No.1884 Sequence
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-21 00:14:48
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 6,672 ms
コンパイル使用メモリ 158,400 KB
実行使用メモリ 208,264 KB
最終ジャッジ日時 2023-11-21 00:15:08
合計ジャッジ時間 19,331 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
33,060 KB
testcase_01 AC 79 ms
33,188 KB
testcase_02 AC 79 ms
33,060 KB
testcase_03 AC 74 ms
32,804 KB
testcase_04 AC 76 ms
32,804 KB
testcase_05 AC 80 ms
33,060 KB
testcase_06 AC 79 ms
33,060 KB
testcase_07 AC 81 ms
33,188 KB
testcase_08 AC 80 ms
33,188 KB
testcase_09 AC 80 ms
33,060 KB
testcase_10 AC 506 ms
65,788 KB
testcase_11 AC 482 ms
65,788 KB
testcase_12 AC 104 ms
45,096 KB
testcase_13 AC 106 ms
45,936 KB
testcase_14 AC 112 ms
45,152 KB
testcase_15 AC 325 ms
53,868 KB
testcase_16 AC 487 ms
65,756 KB
testcase_17 AC 187 ms
49,808 KB
testcase_18 AC 398 ms
55,020 KB
testcase_19 AC 224 ms
51,448 KB
testcase_20 AC 257 ms
52,056 KB
testcase_21 AC 204 ms
48,676 KB
testcase_22 AC 281 ms
53,016 KB
testcase_23 AC 485 ms
65,768 KB
testcase_24 AC 484 ms
65,756 KB
testcase_25 AC 505 ms
64,672 KB
testcase_26 AC 482 ms
65,680 KB
testcase_27 AC 104 ms
46,836 KB
testcase_28 AC 105 ms
46,836 KB
testcase_29 AC 109 ms
47,216 KB
testcase_30 AC 110 ms
47,216 KB
testcase_31 AC 264 ms
50,952 KB
testcase_32 AC 464 ms
64,484 KB
testcase_33 AC 357 ms
65,864 KB
testcase_34 AC 368 ms
65,864 KB
testcase_35 AC 132 ms
48,624 KB
testcase_36 AC 266 ms
56,508 KB
testcase_37 AC 357 ms
65,864 KB
testcase_38 AC 355 ms
62,748 KB
testcase_39 AC 164 ms
48,292 KB
testcase_40 AC 174 ms
49,040 KB
testcase_41 AC 395 ms
60,644 KB
testcase_42 AC 409 ms
208,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (120 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)
    {
        var nonzero = a.Where(ai => ai != 0).ToList();
        if (nonzero.Count < 2)
        {
            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