結果
| 問題 | No.1481 Rotation ABC |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2021-03-21 11:19:16 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 692 bytes |
| 記録 | |
| コンパイル時間 | 193 ms |
| コンパイル使用メモリ | 30,336 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-22 02:31:57 |
| 合計ジャッジ時間 | 1,870 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 10 |
ソースコード
#include <stdio.h>
const int Mod = 998244353;
long long div_mod(long long x, long long y, long long z)
{
if (x % y == 0) return x / y;
else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}
int main()
{
int N;
char S[100001];
scanf("%d", &N);
scanf("%s", S);
int i, count[3] = {};
long long fact[100001];
for (i = 0; S[i] != 0; i++) count[S[i] - 'A']++;
for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
if (count[0] == 0 || count[1] == 0 || count[2] == 0) printf("1\n");
else printf("%lld\n", (div_mod(div_mod(div_mod(fact[N], fact[count[0]], Mod), fact[count[1]], Mod), fact[count[2]], Mod) + Mod - N) % Mod);
fflush(stdout);
return 0;
}