結果

問題 No.1481 Rotation ABC
ユーザー 👑 NachiaNachia
提出日時 2021-04-16 20:19:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,200 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 78,004 KB
実行使用メモリ 5,876 KB
最終ジャッジ日時 2023-09-15 20:45:13
合計ジャッジ時間 2,390 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 7 ms
5,080 KB
testcase_14 AC 7 ms
5,120 KB
testcase_15 AC 6 ms
4,980 KB
testcase_16 AC 6 ms
4,796 KB
testcase_17 AC 5 ms
4,428 KB
testcase_18 AC 7 ms
5,716 KB
testcase_19 AC 5 ms
4,404 KB
testcase_20 AC 5 ms
4,688 KB
testcase_21 AC 7 ms
5,232 KB
testcase_22 AC 5 ms
4,540 KB
testcase_23 AC 8 ms
5,488 KB
testcase_24 AC 8 ms
5,652 KB
testcase_25 AC 8 ms
5,532 KB
testcase_26 AC 8 ms
5,500 KB
testcase_27 AC 8 ms
5,876 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 4 ms
4,384 KB
testcase_34 WA -
testcase_35 AC 4 ms
4,380 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ull M = 998244353;
vector<ull> F,I,iF;

ull powm(ull a,ull i){
  if(i==0) return 1;
  ull res = powm(a*a%M,i/2);
  if(i%2==1) res = res * a % M;
  return res;
}

void initComb(int Z){
  F.resize(Z+1);
  F[0]=1;
  for(int i=1; i<=Z; i++) F[i]=F[i-1]*i%M;
  I.resize(Z+1);
  I[1]=1;
  for(int i=2; i<=Z; i++) I[i]=M-M/i*I[M%i]%M;
  iF.resize(Z+1);
  iF[0]=1;
  for(int i=1; i<=Z; i++) iF[i]=iF[i-1]*I[i]%M;
}

ull Comb(int n,int r){ return F[n]*iF[r]%M*iF[n-r]%M; }

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  string chs = "ABC";
  vector<int> Cchs(chs.size(),0);
  for(char c:S) rep(t,chs.size()) if(chs[t]==c) Cchs[t]++;

  for(char c:chs) if(S.find(c)==string::npos){ cout<<"1\n"; return 0; }

  {
    auto p = S.find('C');
    S = S.substr(p) + S.substr(0,p);
  }

  bool fixed = true;
  rep(i,S.size()-1) if(S[i]<S[i+1]) fixed=false;
  if(fixed){ cout<<"1\n"; return 0; }

  initComb(N);
  ull ans = F[N];
  rep(t,3) ans = ans * iF[Cchs[t]] % M;
  ans = (ans + M - N) %M;
  cout << ans << "\n";

  return 0;
}
0