結果

問題 No.1884 Sequence
ユーザー kenya_hobbkenya_hobb
提出日時 2022-03-26 20:15:53
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,086 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 114,900 KB
実行使用メモリ 58,680 KB
最終ジャッジ日時 2024-04-23 12:30:57
合計ジャッジ時間 9,556 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,424 KB
testcase_01 AC 29 ms
25,140 KB
testcase_02 AC 27 ms
27,472 KB
testcase_03 AC 27 ms
25,520 KB
testcase_04 AC 27 ms
27,324 KB
testcase_05 AC 28 ms
27,456 KB
testcase_06 AC 28 ms
25,412 KB
testcase_07 AC 28 ms
27,212 KB
testcase_08 AC 28 ms
27,460 KB
testcase_09 AC 28 ms
27,604 KB
testcase_10 AC 201 ms
58,680 KB
testcase_11 AC 199 ms
56,372 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 86 ms
32,352 KB
testcase_15 AC 188 ms
45,412 KB
testcase_16 AC 207 ms
58,392 KB
testcase_17 WA -
testcase_18 AC 155 ms
50,440 KB
testcase_19 AC 129 ms
44,060 KB
testcase_20 AC 142 ms
44,148 KB
testcase_21 AC 131 ms
42,580 KB
testcase_22 AC 148 ms
44,768 KB
testcase_23 AC 202 ms
58,536 KB
testcase_24 AC 198 ms
58,640 KB
testcase_25 AC 196 ms
55,276 KB
testcase_26 AC 202 ms
58,304 KB
testcase_27 AC 116 ms
41,892 KB
testcase_28 AC 112 ms
42,140 KB
testcase_29 AC 109 ms
39,712 KB
testcase_30 AC 106 ms
42,132 KB
testcase_31 AC 130 ms
45,568 KB
testcase_32 AC 194 ms
55,496 KB
testcase_33 AC 173 ms
58,628 KB
testcase_34 AC 173 ms
58,628 KB
testcase_35 AC 112 ms
40,852 KB
testcase_36 AC 160 ms
52,332 KB
testcase_37 AC 175 ms
56,448 KB
testcase_38 AC 163 ms
53,420 KB
testcase_39 AC 122 ms
44,192 KB
testcase_40 AC 123 ms
42,980 KB
testcase_41 AC 181 ms
56,020 KB
testcase_42 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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());
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray(); //SelectはLinq
            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