結果

問題 No.2254 Reverse Only
ユーザー 👑 chro_96chro_96
提出日時 2023-03-24 23:49:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,436 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 32,684 KB
実行使用メモリ 9,724 KB
最終ジャッジ日時 2023-10-18 21:42:07
合計ジャッジ時間 3,810 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,724 KB
testcase_01 AC 5 ms
9,724 KB
testcase_02 AC 5 ms
9,724 KB
testcase_03 AC 5 ms
9,724 KB
testcase_04 AC 5 ms
9,724 KB
testcase_05 AC 5 ms
9,724 KB
testcase_06 AC 5 ms
9,724 KB
testcase_07 AC 5 ms
9,724 KB
testcase_08 AC 52 ms
9,724 KB
testcase_09 AC 54 ms
9,724 KB
testcase_10 AC 50 ms
9,724 KB
testcase_11 AC 52 ms
9,724 KB
testcase_12 AC 53 ms
9,724 KB
testcase_13 AC 51 ms
9,724 KB
testcase_14 AC 52 ms
9,724 KB
testcase_15 AC 52 ms
9,724 KB
testcase_16 AC 55 ms
9,724 KB
testcase_17 AC 55 ms
9,724 KB
testcase_18 AC 53 ms
9,724 KB
testcase_19 AC 51 ms
9,724 KB
testcase_20 AC 54 ms
9,724 KB
testcase_21 AC 53 ms
9,724 KB
testcase_22 AC 43 ms
9,724 KB
testcase_23 AC 54 ms
9,724 KB
testcase_24 AC 52 ms
9,724 KB
testcase_25 AC 54 ms
9,724 KB
testcase_26 AC 55 ms
9,724 KB
testcase_27 AC 6 ms
9,724 KB
testcase_28 AC 16 ms
9,724 KB
testcase_29 AC 27 ms
9,724 KB
testcase_30 AC 24 ms
9,724 KB
testcase_31 AC 16 ms
9,724 KB
testcase_32 AC 17 ms
9,724 KB
testcase_33 AC 11 ms
9,724 KB
testcase_34 AC 33 ms
9,724 KB
testcase_35 AC 23 ms
9,724 KB
testcase_36 AC 45 ms
9,724 KB
testcase_37 AC 47 ms
9,724 KB
testcase_38 AC 13 ms
9,724 KB
testcase_39 AC 43 ms
9,724 KB
testcase_40 AC 6 ms
9,724 KB
testcase_41 AC 21 ms
9,724 KB
testcase_42 AC 14 ms
9,724 KB
testcase_43 AC 35 ms
9,724 KB
testcase_44 AC 49 ms
9,724 KB
testcase_45 AC 33 ms
9,724 KB
testcase_46 AC 6 ms
9,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int k = 0;
  int a[200000] = {};
  int b[200000] = {};
  
  int res = 0;
  
  int za[600000] = {};
  int baa[600000] = {};
  
  int cnta[200001] = {};
  int cntb[200001] = {};
  
  int is_ok = 1;
  
  res = scanf("%d", &n);
  res = scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
  }
  for (int i = 0; i < n; i++) {
    res = scanf("%d", b+i);
  }
  
  if (k >= n) {
    int is_ok = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        is_ok = 0;
      }
    }
    if (is_ok > 0) {
      printf("Yes\n");
    } else if (k > n) {
      printf("No\n");
    } else {
      int is_ok = 1;
      for (int i = 0; i < n; i++) {
        if (a[i] != b[n-i-1]) {
          is_ok = 0;
        }
      }
      if (is_ok > 0) {
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    }
    return 0;
  }
  
  if (k == n-1) {
    int i = 1;
    int j = 0;
    int is_ok = 0;
    for (int i = 0; i < n; i++) {
      baa[i] = b[i];
      baa[i+n] = a[i];
      baa[i+2*n] = a[i];
    }
    za[0] = 3*n;
    while (i < 3*n) {
      while (i+j < 3*n && baa[j] == baa[i+j]) {
        j++;
      }
      za[i] = j;
      if (j == 0) {
        i++;
      } else {
        int k = 1;
        while (k < j && k+za[k] < j) {
          za[i+k] = za[k];
          k++;
        }
        i += k;
        j -= k;
      }
    }
    for (int i = n; i < 2*n; i++) {
      if (za[i] >= n) {
        is_ok = 1;
      }
    }
    for (int i = 0; i < n; i++) {
      baa[i] = b[n-i-1];
      baa[i+n] = a[i];
      baa[i+2*n] = a[i];
    }
    za[0] = 3*n;
    i = 1;
    j = 0;
    while (i < 3*n) {
      while (i+j < 3*n && baa[j] == baa[i+j]) {
        j++;
      }
      za[i] = j;
      if (j == 0) {
        i++;
      } else {
        int k = 1;
        while (k < j && k+za[k] < j) {
          za[i+k] = za[k];
          k++;
        }
        i += k;
        j -= k;
      }
    }
    for (int i = n; i < 2*n; i++) {
      if (za[i] >= n) {
        is_ok = 1;
      }
    }
    if (is_ok > 0) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
    return 0;
  }
  
  for (int i = 0; i < n; i++) {
    cnta[a[i]]++;
    cntb[b[i]]++;
  }
  
  for (int i = 0; i <= 200000; i++) {
    if (cnta[i] != cntb[i]) {
      is_ok = 0;
    }
  }
  
  if (is_ok > 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}
0