結果
| 問題 | 
                            No.171 スワップ文字列(Med)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-07-07 15:16:46 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 1,000 ms | 
| コード長 | 1,147 bytes | 
| コンパイル時間 | 554 ms | 
| コンパイル使用メモリ | 61,268 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-08 01:30:15 | 
| 合計ジャッジ時間 | 1,215 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 | 
ソースコード
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
const ll mod = 573;
ll invt[600] = {};
int tot = 0;
int ap[26];
int solve(void) {
  int f3 = 0;
  int f191 = 0;
  ll acc = 1;
  REP(i, 1, tot + 1) {
    int v = i;
    while (v % 3 == 0) {
      v /= 3;
      f3++;
    }
    while (v % 191 == 0) {
      v /= 191;
      f191++;
    }
    acc = acc * v % mod;
  }
  REP(i, 0, 26) {
    REP(j, 1, ap[i] + 1) {
      int v = j;
      while (v % 3 == 0) {
	v /= 3;
	f3--;
      }
      while (v % 191 == 0) {
	v /= 191;
	f191--;
      }
      acc = acc * invt[v % mod] % mod;
    }
  }
  REP(i, 0, f3) {
    acc = acc * 3 % mod;
  }
  REP(i, 0, f191) {
    acc = acc * 191 % mod;
  }
  return (acc + mod - 1) % mod;
}
int main(void){
  REP(i, 1, mod) {
    if (__gcd(i, (int)mod) != 1) {
      continue;
    }
    REP(j, 1, mod) {
      if (i * j % mod == 1) {
	invt[i] = j;
	break;
      }
    }
  }
  string s;
  cin >> s;
  REP(i, 0, s.length()) {
    ap[s[i] - 'A']++;
    tot++;
  }
  cout << solve() << endl;
}