結果

問題 No.1884 Sequence
ユーザー masayamatumasayamatu
提出日時 2022-07-01 20:42:41
言語 C#
(.NET 8.0.203)
結果
RE  
実行時間 -
コード長 5,578 bytes
コンパイル時間 11,165 ms
コンパイル使用メモリ 170,368 KB
実行使用メモリ 228,740 KB
最終ジャッジ日時 2024-05-04 14:38:44
合計ジャッジ時間 25,524 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
30,592 KB
testcase_01 AC 49 ms
30,848 KB
testcase_02 AC 50 ms
30,592 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 51 ms
30,720 KB
testcase_06 AC 50 ms
30,720 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (80 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(int.Parse).ToArray();
            var list = new List<int>();
            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<int>();
            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;
            }
            long gcd = diff[0];
            for (int i = 1; i < diff.Count; i++)
            {
                gcd = MyMath.gcd(gcd, diff[i]);
            }
            int need = 0;
            foreach (var d in diff)
            {
                need += (d / (int)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