結果

問題 No.1707 Simple Range Reverse Problem
ユーザー ripityripity
提出日時 2021-11-07 20:27:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 77,136 KB
実行使用メモリ 43,948 KB
最終ジャッジ日時 2024-04-26 22:02:09
合計ジャッジ時間 7,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
39,992 KB
testcase_01 AC 196 ms
42,320 KB
testcase_02 AC 203 ms
43,136 KB
testcase_03 AC 199 ms
43,060 KB
testcase_04 AC 219 ms
43,288 KB
testcase_05 AC 216 ms
43,344 KB
testcase_06 AC 218 ms
43,584 KB
testcase_07 AC 212 ms
43,416 KB
testcase_08 AC 215 ms
43,712 KB
testcase_09 AC 229 ms
43,368 KB
testcase_10 AC 227 ms
43,524 KB
testcase_11 AC 236 ms
43,140 KB
testcase_12 AC 242 ms
43,600 KB
testcase_13 AC 254 ms
43,948 KB
testcase_14 AC 240 ms
43,200 KB
testcase_15 AC 257 ms
43,776 KB
testcase_16 AC 240 ms
43,628 KB
testcase_17 AC 239 ms
43,012 KB
testcase_18 AC 258 ms
43,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for( int t = 0; t < T; t++ ) {
            int N = sc.nextInt();
            int[] A = new int[2*N];
            int[] X = new int[2*N];
            boolean possible = false;
            boolean first = true;
            for( int i = 0; i < 2*N; i++ ) {
                A[i] = sc.nextInt()-1;
                X[i] = i%N;
                if( A[i] != i%N ) first = false;
            }
            for( int i = 0; i < N; i++ ) {
                rev(N,i,X);
                boolean frag = true;
                for( int j = 0; j < 2*N; j++ ) {
                    if( A[j] != X[j] ) frag = false;
                }
                if( frag ) possible = true;
                rev(N,i,X);
            }
            System.out.println( possible||first ? "Yes" : "No" );
        }
        
    }
    
    static void rev( int N, int k, int[] A ) {
        
        for( int i = 0; i <= N/2; i++ ) {
            int save = A[i+k];
            A[i+k] = A[N+k-i];
            A[N+k-i] = save;
        }
        
    }
    
}
0