結果
問題 | No.1481 Rotation ABC |
ユーザー |
|
提出日時 | 2021-04-24 08:51:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 770 bytes |
コンパイル時間 | 608 ms |
コンパイル使用メモリ | 68,244 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 09:00:57 |
合計ジャッジ時間 | 2,305 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> #include<atcoder/modint> using namespace std; using mint=atcoder::modint998244353; int N; string S; main() { cin>>N>>S; bool a=false,ab=false,abc=false; bool b=false,bc=false,bca=false; bool c=false,ca=false,cab=false; int cnt[3]={}; for(char d:S) { cnt[d-'A']++; if(d=='A') { a=true; if(bc)bca=true; if(c)ca=true; } else if(d=='B') { if(a)ab=true; b=true; if(ca)cab=true; } else { if(ab)abc=true; if(b)bc=true; c=true; } } if(!abc&&!bca&&!cab) { cout<<1<<endl; return 0; } mint ans=1,p=1; for(int i=1;i<=N;i++) { p*=i; if(cnt[0]==i)ans/=p; if(cnt[1]==i)ans/=p; if(cnt[2]==i)ans/=p; } ans*=p; ans-=3; ans-=cnt[0]-1; ans-=cnt[1]-1; ans-=cnt[2]-1; cout<<ans.val()<<endl; }