結果

問題 No.1884 Sequence
ユーザー kenya_hobbkenya_hobb
提出日時 2022-03-25 22:43:52
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,226 bytes
コンパイル時間 2,780 ms
コンパイル使用メモリ 112,780 KB
実行使用メモリ 35,560 KB
最終ジャッジ日時 2024-04-22 07:27:43
合計ジャッジ時間 7,001 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
24,704 KB
testcase_01 AC 30 ms
19,456 KB
testcase_02 AC 30 ms
19,072 KB
testcase_03 AC 30 ms
19,328 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 sa = A[0] - A[1];


            for(int i = 0;i < N - 2; i++)
            {
                if(A[i] - A[i + 1] > A[i + 1] - A[i + 2])
                {
                    if (A[N - 1] == 0)
                        A[N - 1] = A[i + 1] + Math.Min(A[i] - A[i + 1], A[i + 1] - A[i + 2]);
                    else
                    { ok = false; break; }
                    Array.Sort(A);
                    Array.Reverse(A);
                    i = -1;
                }
                else if(A[i] - A[i + 1] < A[i + 1] - A[i + 2])
                {
                    if (A[N - 1] == 0)
                        A[N - 1] = A[i + 1] - Math.Min(A[i] - A[i + 1], A[i + 1] - A[i + 2]);
                    else
                    { ok = false; break; }
                    Array.Sort(A);
                    Array.Reverse(A);
                    i = -1;
                }
            }

            if (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