結果

問題 No.171 スワップ文字列(Med)
ユーザー YoshiRyuYoshiRyu
提出日時 2017-05-17 14:44:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,257 bytes
コンパイル時間 3,437 ms
コンパイル使用メモリ 159,876 KB
実行使用メモリ 11,376 KB
最終ジャッジ日時 2023-10-17 15:00:59
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

// マクロ群
#define REP(i,n) for(int i=0;i<n;++i)
#define REP2(i,a,b) for (int i=(a);i<(b);++i)
#define rep(n) REP(i,n)
#define SF(f,v) scanf(f,v)
#define SF_N(v) SF("%d",&v)
#define SF_S(v) SF("%s",v)
#define PF(f,v) printf(f,v)
#define PFS_N(v) PF("%d ",v)
#define PFS_S(v) PF("%s ",v)
#define PFL_N(v) PF("%d\n",v)
#define PFL_S(v) PF("%s\n",v)

typedef long long ll;

static ll tri[1010][1010] = { 0 }, memo['Z' + 1] = { 0 };
static int len = 0, ans = 1, MOD = 573;

using namespace std;
void Solve()
{
	string S;
	cin >> S;
	
	// 全体と個別の文字をカウント
	for (auto itr = S.begin(); itr != S.end(); ++itr)
	{
		++memo[*itr];
		++len;
	}

	// パスカルの三角形
	for (int i = 1; i <= len; ++i)
	{
		tri[i][0] = 1;	// 三角形の外側の辺は必ず1
		REP2(j, 1, i)
		{
			tri[i][j] = (tri[i - 1][j - 1] + tri[i - 1][j]) % MOD;
		}
		tri[i][i] = 1;	// 三角形の外側の辺は必ず1
	}

	for (int c = 'A'; len > 0; ++c)
	{
		if (!memo[c]) continue;
		
		ans = ans * tri[len][memo[c]] % MOD;
		len -= memo[c];
	}

	// ゼロ除算の回避。MODを足した結果に対して-1を行うことで、最小値が1に留まる
	PFL_N( (ans + MOD - 1) % MOD );
}

int main() { Solve(); return 0; }
0