結果

問題 No.171 スワップ文字列(Med)
ユーザー ty70ty70
提出日時 2015-03-30 16:04:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 2,068 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 95,544 KB
実行使用メモリ 11,536 KB
最終ジャッジ日時 2023-09-17 00:21:42
合計ジャッジ時間 1,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,536 KB
testcase_01 AC 9 ms
11,316 KB
testcase_02 AC 9 ms
11,312 KB
testcase_03 AC 9 ms
11,256 KB
testcase_04 AC 9 ms
11,244 KB
testcase_05 AC 9 ms
11,328 KB
testcase_06 AC 9 ms
11,260 KB
testcase_07 AC 10 ms
11,300 KB
testcase_08 AC 9 ms
11,536 KB
testcase_09 AC 9 ms
11,284 KB
testcase_10 AC 9 ms
11,452 KB
testcase_11 AC 9 ms
11,244 KB
testcase_12 AC 9 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define each(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizoef(a))
#define sz(s) (int)((s).size())
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define pb push_back
#define MP(x,y) make_pair((x),(y))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 573;
const int MAX_N = 1005;

ll dp[MAX_N][MAX_N];
void init_comb (void ){
	memset (dp, 0, sizeof (dp ) );
	
	dp[0][0] = 1LL;
	for (int i = 1; i < MAX_N; i++ ){
		for (int j = 0; j <= i; j++ ){
			dp[i-j][j] = (dp[i-j][j] + (i-j-1 >= 0 ? dp[i-j-1][j] : 0LL ) ) % MOD;
			dp[i-j][j] = (dp[i-j][j] + (  j-1 >= 0 ? dp[i-j][j-1] : 0LL ) ) % MOD;
		} // end for
	} // end for		
}

ll comb (int n, int r ){
	return (n >= r ? dp[n-r][r] : 0LL );
}

int main()
{
	init_comb();
	ios_base::sync_with_stdio(0);
	string s; cin >> s;
	map<char,int> cnt; cnt.clear();
	int n = s.length();
	rep (i, n ){
		cnt[s[i]]++;
	} // end rep

	ll res = 1LL;
	map<char,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); it++ ){
		char c = (*it).first;
		int  k = (*it).second;
		ll curr = comb (n, k );
		res = (res * curr ) % MOD;
		n -= k;
	} // end for
	cout << (res - 1LL + MOD ) % MOD << endl;

	return 0;
}
0