結果

問題 No.1707 Simple Range Reverse Problem
ユーザー bluemeganebluemegane
提出日時 2021-10-16 09:30:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 4,756 ms
コンパイル使用メモリ 110,516 KB
実行使用メモリ 25,652 KB
最終ジャッジ日時 2023-10-17 22:04:13
合計ジャッジ時間 2,175 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,048 KB
testcase_01 AC 29 ms
25,044 KB
testcase_02 AC 29 ms
25,048 KB
testcase_03 AC 29 ms
25,048 KB
testcase_04 AC 29 ms
25,048 KB
testcase_05 AC 28 ms
25,048 KB
testcase_06 AC 29 ms
25,048 KB
testcase_07 AC 29 ms
25,052 KB
testcase_08 AC 29 ms
25,052 KB
testcase_09 AC 33 ms
25,612 KB
testcase_10 AC 33 ms
25,612 KB
testcase_11 AC 32 ms
25,612 KB
testcase_12 AC 32 ms
25,612 KB
testcase_13 AC 33 ms
25,652 KB
testcase_14 AC 33 ms
25,612 KB
testcase_15 AC 33 ms
25,612 KB
testcase_16 AC 33 ms
25,616 KB
testcase_17 AC 32 ms
25,612 KB
testcase_18 AC 33 ms
25,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        var t = int.Parse(Console.ReadLine().Trim());
        while (t-- > 0)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            string[] line = ("0 " + Console.ReadLine().Trim()).Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            getAns(n, a);
        }
    }
    static int[] change(int n, int t)
    {
        var a = new int[2 * n + 1];
        var b = new int[2 * n + 1];
        for (int i = 1; i <= n; i++)
        {
            a[i] = i; a[i + n] = i;
            b[i] = i; b[i + n] = i;
        }
        var p = t + n - 1;
        var imax = p;
        for (int i = t + 1; i <= imax; i++) a[i] = b[p--];
        return a;
    }
    static bool check(int n, int[] a, int t)
    {
        var b = change(n, t);
        for (int i = 1; i <= 2 * n; i++)
        {
            if (a[i] != b[i]) return false;
        }
        return true;
    }
    static void getAns(int n, int[] a)
    {
        var ok = true;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] != a[i + n]) { ok = false; break; }
            if (a[i] != i ) { ok = false; break; }
        }
        if (ok) { Console.WriteLine("Yes"); return; }
        var b = new List<int>();
        for (int i = 1; i <= n; i++)
            if (a[i] == a[i + n]) b.Add(i);
        if (b.Count() == 0) { Console.WriteLine("No"); return; }
        foreach(var x in b)
        {
            if (check(n, a, x)) { Console.WriteLine("Yes"); return; }
        }
        Console.WriteLine("No");
    }
}
0