結果

問題 No.1884 Sequence
ユーザー kenya_hobbkenya_hobb
提出日時 2022-03-26 20:30:11
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 3,176 bytes
コンパイル時間 6,528 ms
コンパイル使用メモリ 168,592 KB
実行使用メモリ 224,192 KB
最終ジャッジ日時 2024-04-23 12:51:01
合計ジャッジ時間 13,270 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
29,824 KB
testcase_01 AC 48 ms
29,440 KB
testcase_02 AC 47 ms
29,696 KB
testcase_03 AC 47 ms
29,820 KB
testcase_04 AC 49 ms
29,696 KB
testcase_05 AC 50 ms
29,948 KB
testcase_06 AC 50 ms
29,440 KB
testcase_07 AC 49 ms
29,696 KB
testcase_08 AC 47 ms
29,568 KB
testcase_09 AC 49 ms
29,696 KB
testcase_10 AC 193 ms
68,204 KB
testcase_11 AC 167 ms
68,208 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 105 ms
41,728 KB
testcase_15 AC 146 ms
55,424 KB
testcase_16 AC 173 ms
68,224 KB
testcase_17 WA -
testcase_18 AC 140 ms
56,684 KB
testcase_19 AC 126 ms
52,720 KB
testcase_20 AC 142 ms
53,248 KB
testcase_21 AC 127 ms
48,640 KB
testcase_22 AC 141 ms
54,400 KB
testcase_23 AC 168 ms
68,352 KB
testcase_24 AC 163 ms
68,224 KB
testcase_25 AC 165 ms
67,200 KB
testcase_26 AC 166 ms
67,840 KB
testcase_27 AC 106 ms
43,520 KB
testcase_28 AC 109 ms
44,032 KB
testcase_29 AC 115 ms
43,520 KB
testcase_30 AC 112 ms
43,904 KB
testcase_31 AC 130 ms
52,096 KB
testcase_32 AC 162 ms
67,200 KB
testcase_33 AC 132 ms
68,464 KB
testcase_34 AC 128 ms
68,608 KB
testcase_35 AC 112 ms
45,824 KB
testcase_36 AC 134 ms
62,068 KB
testcase_37 AC 134 ms
68,464 KB
testcase_38 AC 127 ms
65,280 KB
testcase_39 AC 116 ms
48,384 KB
testcase_40 AC 120 ms
51,068 KB
testcase_41 AC 161 ms
63,872 KB
testcase_42 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (81 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.Generic;
using System.Linq;
using System.IO;

namespace ConsoleApp1
{
    class Program
    {
        //private static int[] A = new int[200005];//MargeSort用
        //private static int[] C = new int[200005];

        static void Main(string[] args)
        {
			long N = long.Parse(Console.ReadLine());
            string[] line = Console.ReadLine().Trim().Split(' ');
            long[] A = new long[N];
            for (int i = 0; i < N; i++)
                A[i] = long.Parse(line[i]);
            bool ok = true;

            Array.Sort(A);
            Array.Reverse(A);
            long kousa = A[0] - A[1];
            long need_zero = 0;


            for(int i = 1; i < N - 1; i++)
            {
                if (A[i + 1] != 0 && A[i] != 0)
                {
                    if (A[i] - A[i + 1] == 0 || kousa == 0)
                    { kousa = 0; break; }
                    else
                        kousa = GCD(kousa, A[i] - A[i + 1]);

                }
            }

            for (int i = 0; i < N - 1; i++)
            {
                if (A[i] - A[i + 1] != kousa && A[i] != 0 && A[i + 1] != 0)
                    if (kousa == 0)
                        ok = false;
                    else
                        need_zero += (A[i] - A[i + 1]) / kousa;
            }


            if (need_zero <= A.Count(x => x == 0) && ok)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }

        static long GCD(long a, long b)//公約数 再起関数にしてみるいつか
        {
            while (a > 0 && b > 0)
            {
                if (a > b)
                    a = a % b;
                else
                    b = b % a;
            }

            if (a == 0)
                return b;
            else
                return a;
        }

        static long LCD(long a, long b)
        {
            return a / GCD(a, b) * b;
        }


        //static void MargeSort(int l, int r)//A配列とC配列(ソート後)を用意する必要あり
        //{
        //    if (r - l == 1) return;

        //    int m = (l + r) / 2;
        //    MargeSort(l, m);
        //    MargeSort(m, r);

        //    int c1 = l, c2 = m, cnt = 0;
        //    while(c1 != m || c2 != r)
        //    {
        //        if(c1 == m)
        //        {
        //            C[cnt] = A[c2];
        //            c2++;
        //        }
        //        else if(c2 == r)
        //        {
        //            C[cnt] = A[c1];
        //            c1++;
        //        }
        //        else
        //        {
        //            if (A[c1] <= A[c2])
        //            {
        //                C[cnt] = A[c1];
        //                c1++;
        //            }
        //            else
        //            {
        //                C[cnt] = A[c2];
        //                c2++;
        //            }
        //        }

        //        cnt++;

        //    }

        //    for(int i = 0; i < cnt; i++)
        //    {
        //        A[l + i] = C[i];
        //    }

        //}

    }
}
0