結果

問題 No.171 スワップ文字列(Med)
ユーザー ty70ty70
提出日時 2015-03-23 00:20:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,111 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 95,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 09:40:43
合計ジャッジ時間 1,461 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 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 = 573LL;
const int MAX_P=1005;

int fact[MAX_P], rfact[MAX_P];

ll extgcd (ll a, ll b, ll &x, ll &y ){
	if (b == 0 ){x = 1LL; y = 0LL; return a; }
	ll g = extgcd (b, a%b, y, x ); y -= a/b*x;
	return g;
}

ll mod_inv (ll a, ll M ){
	ll x, y;
	extgcd (a, M, x, y );
	return (M+x%M)%M;
}

void init (void ){
	fact[0] = rfact[0] = 1;
	for (int i = 1; i < MAX_P; i++ ){
		fact[i] = ((ll)fact[i-1]*i)%MOD;
		rfact[i] = ((ll)rfact[i-1]*mod_inv((ll)i,(ll)MOD))%MOD;
	} // end for
}

int main()
{
	ios_base::sync_with_stdio(0);
	init ();
	string S = ""; cin >> S;
	map<char,int> cnt; cnt.clear();
	rep (i, S.length() ){
		cnt[S[i]]++;
	} // end rep
	ll res = (ll)(fact[S.length()]%MOD);
	map<char,int>::iterator it = cnt.begin();
	for(; it != cnt.end(); it++ ){
		char c = (*it).first;
		int  n = (*it).second;
		if (n == 0 || n == 1 ) continue;
		res = (res*(ll)rfact[n])%MOD;
	} // end for
	cout << (res - 1LL + MOD ) % MOD << endl;

	return 0;
}
0