結果
問題 | No.171 スワップ文字列(Med) |
ユーザー |
![]() |
提出日時 | 2015-03-22 23:43:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,421 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 57,528 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 00:14:01 |
合計ジャッジ時間 | 855 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
// Wrongri-La Shower#include <cstdio>#include <iostream>typedef std::tuple<int,int,int> T;typedef long long ll;// 573: 3 191int count[26], inv[573];int mod_pow(int a, int n){int res = 1;while(n > 0){if(n & 1){res = res * a % 573;}n >>= 1;a = a * a % 573;}return res;}int nCk(int n, int k){if(n < k){return 0ll;}int n3 = 0, n191 = 0, other = 1;for(int i=n-k+1;i<=n;i++){int x = i;while(x % 3 == 0){++n3; x /= 3;}while(x % 191 == 0){++n191; x /= 191;}other = other * x % 573;}int other2 = 1;for(int i=1;i<=k;i++){int x = i;while(x % 3 == 0){--n3; x /= 3;}while(x % 191 == 0){--n191; x /= 191;}other2 = other2 * x % 573;}return mod_pow(3, n3) * mod_pow(191, n191) % 573 * other % 573 * inv[other2] % 573;}int main(){for(int i=0;i<573;i++){for(int j=0;j<573;j++){if(i * j % 573 == 1){inv[i] = j; break;}}}std::string S;std::cin >> S;for(char c : S){count[c-'A'] += 1;}int res = 1ll;int sum = 0;for(int i=0;i<26;i++){res = res * nCk(S.size()-sum, count[i]) % 573;sum += count[i];}printf("%d\n", (res+573-1) % 573);}