結果

問題 No.171 スワップ文字列(Med)
ユーザー koba-e964koba-e964
提出日時 2015-07-07 15:16:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,147 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 62,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 09:20:38
合計ジャッジ時間 1,247 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0