結果

問題 No.171 スワップ文字列(Med)
ユーザー vain0vain0
提出日時 2015-05-24 23:56:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 805 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 70,908 KB
実行使用メモリ 7,556 KB
最終ジャッジ日時 2023-09-20 12:50:52
合計ジャッジ時間 1,268 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,464 KB
testcase_01 AC 5 ms
7,320 KB
testcase_02 AC 5 ms
7,408 KB
testcase_03 AC 5 ms
7,268 KB
testcase_04 AC 5 ms
7,348 KB
testcase_05 AC 5 ms
7,244 KB
testcase_06 AC 5 ms
7,276 KB
testcase_07 AC 5 ms
7,296 KB
testcase_08 AC 4 ms
7,272 KB
testcase_09 AC 5 ms
7,376 KB
testcase_10 AC 5 ms
7,556 KB
testcase_11 AC 5 ms
7,320 KB
testcase_12 AC 5 ms
7,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))

static int const MOD = 573;
static int const COMBI_MAX = 1002;
static int combi[COMBI_MAX][COMBI_MAX];

int cnts['Z' - 'A' + 1];

int main() {
	string s;
	cin >> s;
	int n = s.size();
	rep(i, n) { cnts[s[i] - 'A'] ++; }

	rep(i, COMBI_MAX) repi(j, 0, i/2 + 1) {
		combi[i][j] = combi[i][i - j] =
			(i == 0 || j == 0) ? 1
			: (combi[i - 1][j] + combi[i - 1][j - 1]) % MOD;
	}

	int m = n;
	int res = 1;
	rep(i, 'Z' - 'A' + 1) {
		int r = cnts[i];
		res = (res * combi[m][r]) % MOD;
		m -= r;
	}
	cout << (res + MOD - 1) % MOD << endl;
	return 0;
}
0