結果

問題 No.1884 Sequence
ユーザー masayamatumasayamatu
提出日時 2022-07-01 21:06:27
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 5,708 bytes
コンパイル時間 8,981 ms
コンパイル使用メモリ 167,448 KB
実行使用メモリ 231,320 KB
最終ジャッジ日時 2024-05-04 15:04:13
合計ジャッジ時間 17,098 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
30,848 KB
testcase_01 AC 64 ms
30,976 KB
testcase_02 AC 63 ms
30,976 KB
testcase_03 AC 59 ms
30,336 KB
testcase_04 AC 61 ms
30,592 KB
testcase_05 AC 62 ms
30,848 KB
testcase_06 AC 63 ms
30,848 KB
testcase_07 AC 64 ms
30,848 KB
testcase_08 AC 62 ms
30,848 KB
testcase_09 AC 63 ms
30,848 KB
testcase_10 AC 222 ms
82,088 KB
testcase_11 AC 227 ms
81,920 KB
testcase_12 AC 98 ms
42,744 KB
testcase_13 AC 99 ms
43,648 KB
testcase_14 AC 100 ms
43,264 KB
testcase_15 AC 165 ms
58,672 KB
testcase_16 AC 224 ms
81,912 KB
testcase_17 AC 128 ms
55,672 KB
testcase_18 AC 162 ms
59,768 KB
testcase_19 AC 136 ms
56,568 KB
testcase_20 AC 151 ms
56,960 KB
testcase_21 AC 130 ms
52,856 KB
testcase_22 AC 159 ms
57,472 KB
testcase_23 AC 229 ms
82,048 KB
testcase_24 AC 226 ms
81,960 KB
testcase_25 AC 229 ms
80,896 KB
testcase_26 AC 225 ms
81,920 KB
testcase_27 AC 97 ms
44,544 KB
testcase_28 AC 100 ms
44,664 KB
testcase_29 AC 99 ms
44,672 KB
testcase_30 AC 101 ms
44,928 KB
testcase_31 AC 150 ms
55,800 KB
testcase_32 AC 214 ms
80,256 KB
testcase_33 AC 177 ms
82,176 KB
testcase_34 AC 180 ms
82,176 KB
testcase_35 AC 108 ms
47,996 KB
testcase_36 AC 154 ms
70,656 KB
testcase_37 AC 201 ms
82,304 KB
testcase_38 AC 194 ms
78,976 KB
testcase_39 AC 126 ms
51,968 KB
testcase_40 AC 131 ms
55,424 KB
testcase_41 AC 200 ms
75,392 KB
testcase_42 AC 198 ms
231,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (103 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
//using static CompLib.CompLib;
//using DataStructure;

namespace atcoder
{
    class Program
    {
        const int intMax = 1000000000;
        const long longMax = 2000000000000000000;
        static void Main(string[] args)
        {
           int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var list = new List<long>();
            int cnt = 0;
            for (int i = 0; i < N; i++)
            {
                if (A[i] > 0)
                {
                    list.Add(A[i]);
                }
                else
                {
                    cnt++;
                }
            }
            list = list.OrderBy(a => a).ToList();
            var diff = new List<long>();
            for (int i = 0; i < list.Count - 1; i++)
            {
                diff.Add(list[i + 1] - list[i]);
            }
            if (diff.Contains(0))
            {
                if (list[0] == list[list.Count - 1])
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
                return;
            }
            else if (diff.Count == 0)
            {
                Console.WriteLine("Yes");
                return;
            }
            long gcd = diff[0];
            for (int i = 1; i < diff.Count; i++)
            {
                gcd = MyMath.gcd(gcd, diff[i]);
            }
            long need = 0;
            foreach (var d in diff)
            {
                need += (d / gcd) - 1;
            }
            if (need <= cnt)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
    public static class MyMath
    {
        public static bool IsPrime(long n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        public static List<int> GetPrimes(int n)
        {
            var primeList = new List<int>();
            var prime = new int[n + 1];
            for (int i = 2; i <= n; i++)
            {
                int temp = i;
                int id = 2;
                while (temp <= n)
                {
                    prime[temp]++;
                    temp = i * id;
                    id++;
                }
            }
            for (int i = 1; i <= n; i++)
            {
                if (prime[i] == 1)
                {
                    primeList.Add(i);
                }
            }
            return primeList;
        }
        public static long gcd(long C, long D)
        {
            long tempC = C;
            long tempD = D;

            long r = tempD % tempC;
            while (r != 0)
            {
                tempD = tempC;
                tempC = r;
                r = tempD % tempC;
            }
            return tempC;
        }
        public static long lcm(long C, long D)
        {
            long tempC = C;
            long tempD = D;

            long r = tempD % tempC;
            while (r != 0)
            {
                tempD = tempC;
                tempC = r;
                r = tempD % tempC;
            }
            long lcm = (long)Math.Floor(((decimal)C * D) / tempC);
            return lcm;
        }
        public static long pow(long x, long n, long mod = 100000007)
        {
            long ret = 1;
            while (n > 0)
            {
                if ((n & 1) > 0) ret *= x;
                ret %= mod;
                x *= x;
                x %= mod;
                n = n >> 1;
            }
            return ret;
        }
        public static long[,] Transpose(long[,] A)
        {
            long[,] AT = new long[A.GetLength(1), A.GetLength(0)];
            for (int i = 0; i < A.GetLength(1); i++)
            {
                for (int j = 0; j < A.GetLength(0); j++)
                {
                    AT[i, j] = A[j, i];
                }
            }
            return AT;
        }
        public static long[,] MatrixMultiplication(long[,] A, long[,] B, long mod = 1000000007)
        {
            long[,] C = new long[A.GetLength(0), B.GetLength(1)];
            for (int i = 0; i < A.GetLength(0); i++)
            {
                for (int j = 0; j < B.GetLength(1); j++)
                {
                    for (int k = 0; k < A.GetLength(1); k++)
                    {
                        C[i, j] += A[i, k] * B[k, j];
                        C[i, j] %= mod;
                    }
                }
            }
            return C;
        }
        public static long[,] MathrixPow(long[,] A, long n, long mod = 1000000007)
        {
            long[,] P = A;
            long[,] Q = new long[A.GetLength(0), A.GetLength(1)];
            bool flag = false;
            for (int i = 0; i < 60; i++)
            {
                if ((n & ((long)1 << i)) > 0)
                {
                    if (!flag)
                    {
                        Q = P;
                        flag = true;
                    }
                    else
                    {
                        Q = MatrixMultiplication(Q, P, mod);
                    }
                }
                P = MatrixMultiplication(P, P, mod);
            }
            return Q;

        }
    }
}
0