結果
| 問題 | No.1481 Rotation ABC |
| コンテスト | |
| ユーザー |
nok0
|
| 提出日時 | 2021-02-27 10:39:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,073 bytes |
| 記録 | |
| コンパイル時間 | 3,655 ms |
| コンパイル使用メモリ | 254,360 KB |
| 最終ジャッジ日時 | 2025-01-19 07:45:37 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 25 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint1000000007;
const int CombMAX = 3000000;
std::vector<mint> fac(CombMAX + 1), finv(CombMAX + 1), inv(CombMAX + 1);
struct Combinationinit {
Combinationinit() {
const int MOD = mint::mod();
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for(int i = 2; i <= CombMAX; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = MOD - inv[MOD % i] * (MOD / i);
finv[i] = finv[i - 1] * inv[i];
}
}
} Combinationinit_;
int main() {
int n;
string s;
cin >> n >> s;
int count_a = count(s.begin(), s.end(), 'A');
int count_b = count(s.begin(), s.end(), 'B');
int count_c = count(s.begin(), s.end(), 'C');
s += s;
bool can_operation = 0, exist_a = 0, exist_ab = 0;
for(auto &c : s) {
if(c == 'A') exist_a = 1;
if(c == 'B' and exist_a) exist_ab = 1;
if(c == 'C' and exist_ab) can_operation = 1;
}
if(can_operation) {
mint res = fac[n] * finv[count_a] * finv[count_b] * finv[count_c] - n;
cout << res.val() << endl;
} else
cout << 1 << endl;
}
nok0