結果

問題 No.1481 Rotation ABC
ユーザー pockynypockyny
提出日時 2021-04-17 00:28:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,919 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 88,496 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-16 04:23:05
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>

using namespace std;
set<string> st;
void solve(string t){
    if(st.count(t)) return;
    st.insert(t);
    int i,j,k,n = t.size();
    for(i=0;i<n;i++){
        for(j=i + 1;j<n;j++){
            for(k=j + 1;k<n;k++){
                if(t[i]=='A' && t[j]=='B' && t[k]=='C'){
                    string u = t;
                    u[i] = 'B',u[j] = 'C',u[k] = 'A';
                    solve(u);
                }
                if(t[i]=='B' && t[j]=='C' && t[k]=='A'){
                    string u = t;
                    u[i] = 'C',u[j] = 'A',u[k] = 'B';
                    solve(u);
                }
                if(t[i]=='C' && t[j]=='A' && t[k]=='B'){
                    string u = t;
                    u[i] = 'A',u[j] = 'B',u[k] = 'C';
                    solve(u);
                }
            }
        }
    }
}

typedef long long ll;
ll mod = 998244353,f[200010];
ll pw(ll a,ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

int main(){
    int i,n; string s;
    cin >> n >> s;
    int a = 0,ab = 0,abc = 0,b = 0,bc = 0,bca = 0,c = 0,ca = 0,cab = 0;
    vector<ll> cnt(3);
    for(i=0;i<s.size();i++){
        cnt[s[i] - 'A']++;
        if(s[i]=='A'){
            a = 1;
            if(bc) bca = 1;
            if(c) ca = 1;
        }
        if(s[i]=='B'){
            b = 1;
            if(a) ab = 1;
            if(ca) cab = 1;
        }
        if(s[i]=='C'){
            c = 1;
            if(ab) abc = 1;
            if(b) bc = 1;
        }
    }
    if(!abc && !bca && !cab){
        cout << 1 << endl;
        return 0;
    }
    f[0] = 1;
    for(i=1;i<=n;i++) f[i] = (f[i - 1]*i)%mod;
    ll ans = f[n];
    for(i=0;i<3;i++) (ans *= pw(cnt[i],mod - 2)) %= mod;
    (ans += mod - n) %= mod;
    cout << ans << endl;
}
0