提出 #33627134


ソースコード 拡げる

// Author: Ruhan Habib (ruhanhabib39@gmail.com)

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 2e5;

bool dp[MAXN + 10][2][2];

bool solve (int n, string s) {
   vector<int> x(n);
   for (int i = 0; i < n; i++) {
      x[i] = int(s[i] == 'B');
   }

   for (int l = 0; l < 2; l++) {
      for (int r = 0; r < 2; r++) {
         dp[1][l][r] = l == r;
      }
   }


   int m1 = (n - 1) / 2, m2 = n / 2;
   int k;
   for (k = 2; m1 - (k - 1) >= 0 && m2 + (k - 1) < n; k++) {
      int i = m1 - (k - 1), j = m2 + (k - 1);

      for (int l : {0,1}) {
         for (int r : {0, 1}) {
            dp[k][l][r] = l == r && dp[k-1][x[i+1]][x[j-1]];
            if ((n & 1) && (k == 2)) {
               dp[k][l][r] |= 0 == r && dp[k-1][1][1];
               dp[k][l][r] |= l == 1 && dp[k-1][0][0];
            } else {
               dp[k][l][r] |= 0 == r && dp[k-1][1][x[j-1]];
               dp[k][l][r] |= l == 1 && dp[k-1][x[i+1]][0];
            }
         }
      }
   }
   k--;

   return dp[k][x[0]][x[n-1]];
}

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);

   int n; cin >> n;
   string s; cin >> s;
   bool res = solve(n, s);
   if (res) cout << "Yes\n";
   else cout << "No\n";
}

提出情報

提出日時
問題 A - AB Palindrome
ユーザ ruhanhabib39
言語 C++ (GCC 9.2.1)
得点 0
コード長 1314 Byte
結果 WA
実行時間 22 ms
メモリ 4900 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 400
結果
AC × 2
AC × 23
WA × 2
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 03_max_01.txt, 03_max_02.txt, 03_max_03.txt, 03_max_04.txt, 03_max_05.txt, 03_max_06.txt, 03_max_07.txt, 03_max_08.txt, 03_max_09.txt, 03_max_10.txt, 03_max_11.txt, 03_max_12.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 22 ms 3480 KiB
00_sample_02.txt AC 2 ms 3604 KiB
01_small_01.txt AC 2 ms 3532 KiB
01_small_02.txt AC 2 ms 3504 KiB
01_small_03.txt AC 3 ms 3604 KiB
01_small_04.txt AC 2 ms 3640 KiB
02_random_01.txt WA 6 ms 4268 KiB
02_random_02.txt AC 10 ms 4592 KiB
02_random_03.txt AC 11 ms 4760 KiB
02_random_04.txt AC 3 ms 3612 KiB
02_random_05.txt AC 11 ms 4648 KiB
02_random_06.txt AC 4 ms 3696 KiB
02_random_07.txt AC 5 ms 3808 KiB
03_max_01.txt AC 10 ms 4744 KiB
03_max_02.txt AC 10 ms 4892 KiB
03_max_03.txt AC 13 ms 4848 KiB
03_max_04.txt AC 11 ms 4876 KiB
03_max_05.txt AC 8 ms 4900 KiB
03_max_06.txt AC 9 ms 4696 KiB
03_max_07.txt AC 12 ms 4856 KiB
03_max_08.txt AC 10 ms 4880 KiB
03_max_09.txt WA 9 ms 4788 KiB
03_max_10.txt AC 7 ms 4792 KiB
03_max_11.txt AC 7 ms 4760 KiB
03_max_12.txt AC 7 ms 4892 KiB