結果

問題 No.2524 Stripes
ユーザー SSRSSSRS
提出日時 2023-10-27 22:21:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,103 ms / 7,000 ms
コード長 1,803 bytes
コンパイル時間 4,018 ms
コンパイル使用メモリ 252,316 KB
実行使用メモリ 16,132 KB
最終ジャッジ日時 2023-10-27 22:21:33
合計ジャッジ時間 15,273 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 579 ms
11,240 KB
testcase_04 AC 23 ms
4,348 KB
testcase_05 AC 398 ms
7,732 KB
testcase_06 AC 589 ms
11,160 KB
testcase_07 AC 1,004 ms
14,980 KB
testcase_08 AC 1,039 ms
15,152 KB
testcase_09 AC 202 ms
5,920 KB
testcase_10 AC 519 ms
10,172 KB
testcase_11 AC 22 ms
4,348 KB
testcase_12 AC 131 ms
5,568 KB
testcase_13 AC 1,098 ms
16,132 KB
testcase_14 AC 1,101 ms
16,132 KB
testcase_15 AC 1,103 ms
16,132 KB
testcase_16 AC 1,101 ms
16,132 KB
testcase_17 AC 1,098 ms
16,132 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/convolution>
using namespace std;
const long long MOD = 998244353;
vector<long long> operator +(vector<long long> A, vector<long long> B){
  int N = A.size();
  int M = B.size();
  int mx = max(N, M);
  vector<long long> ans(mx, 0);
  for (int i = 0; i < N; i++){
    ans[i] += A[i];
  }
  for (int i = 0; i < M; i++){
    ans[i] += B[i];
    ans[i] %= MOD;
  }
  return ans;
}
vector<long long> operator *(vector<long long> A, vector<long long> B){
  return atcoder::convolution(A, B);
}
struct mat{
  array<array<vector<long long>, 2>, 2> f;
  mat(){
    for (int i = 0; i < 2; i++){
      for (int j = 0; j < 2; j++){
        f[i][j] = {0, 0};
      }
    }
  }
  array<vector<long long>, 2>& operator [](int i){
    return f[i];
  }
};
mat operator *(mat L, mat R){
  mat ans;
  ans[0][0] = L[0][0] + R[0][0] + L[0][0] * R[1][0] + L[0][1] * R[0][0];
  ans[0][1] = L[0][1] + R[0][1] + L[0][0] * R[1][1] + L[0][1] * R[0][1];
  ans[1][0] = L[1][0] + R[1][0] + L[1][0] * R[1][0] + L[1][1] * R[0][0];
  ans[1][1] = L[1][1] + R[1][1] + L[1][0] * R[1][1] + L[1][1] * R[0][1];
  return ans;
}
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  auto dfs = [&](auto dfs, int L, int R) -> mat {
    if (R - L == 1){
      mat ans;
      if (S[L] == 'R'){
        ans[0][0][1] = 1;
      }
      if (S[L] == 'B'){
        ans[1][1][1] = 1;
      }
      return ans;
    } else {
      int m = (L + R) / 2;
      return dfs(dfs, L, m) * dfs(dfs, m, R);
    }
  };
  mat p = dfs(dfs, 0, N);
  vector<long long> ans(N + 1, 0);
  for (int i = 0; i < 2; i++){
    for (int j = 0; j < 2; j++){
      for (int k = 0; k <= N; k++){
        ans[k] += p[i][j][k];
        ans[k] %= MOD;
      }
    }
  }
  for (int i = 1; i <= N; i++){
    cout << ans[i] << endl;
  }
}
0