結果

問題 No.2490 Escalator
ユーザー Sillpherth
提出日時 2025-04-21 15:12:17
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,611 bytes
コンパイル時間 4,428 ms
コンパイル使用メモリ 81,360 KB
実行使用メモリ 77,544 KB
最終ジャッジ日時 2025-04-21 15:12:36
合計ジャッジ時間 16,284 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 10 TLE * 1 -- * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class SymmetryChecker {
    static boolean match(int a, int b) {
        return a == b || a == -1 || b == -1;
    }

    static boolean hasSubstrWithAtMostHalfMismatch(int[] text, int[] pattern) {
    	int mismatch = 0;
        int n = pattern.length;
        for (int i = 0; i <= text.length - n; i++) {
            //temp_i = i;
            for (int j = 0; j < n; j++) {
            	//System.out.printf("%d %d %s\n", text[i+j], pattern[j], match(text[i + j], pattern[j])?"true":"false");
                if (!match(text[i + j], pattern[j])) {
                    mismatch++;
                    if (mismatch > (n/2 -1 )) break;
                }
            }
            if (mismatch <= (n/2 - 1)) return true;
            mismatch = 0;
        }
        return false;
    }

    static boolean existsCentrallySymmetricRotation(int[] A) {
        int N = A.length / 2;
        int[] revA = new int[2 * N];
        for (int i = 0; i < 2 * N; i++) {
            revA[i] = A[2 * N - 1 - i];
        }

        int[] AA = new int[4 * N];
        for (int i = 0; i < 2 * N; i++) {
            AA[i] = A[i];
            AA[i + 2 * N] = A[i];
        }

        return hasSubstrWithAtMostHalfMismatch(AA, revA);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = 2 * sc.nextInt();
        int[] A = new int[len];
        for (int i = 0; i < len; i++) {
            A[i] = sc.nextInt();
        }
        boolean result = existsCentrallySymmetricRotation(A);
        System.out.println(result ? "Yes" : "No");
    }
}
0