結果

問題 No.171 スワップ文字列(Med)
ユーザー koyumeishikoyumeishi
提出日時 2015-03-22 23:49:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,467 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 89,544 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 09:37:16
合計ジャッジ時間 1,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

vector<pair<long long, long long> > prime_factorization(long long N){
	vector< pair<long long, long long> > ret;
	
	for(long long i=2; i*i<=N; i++){
		long long tmp = 0;
		while(N%i==0){
			tmp++;
			N/=i;
		}
		if(tmp>0){
			ret.push_back( make_pair(i, tmp) );
		}
	}
	if(N!=1){
		ret.push_back( make_pair(N, 1) );
	}
	return ret;
}


map<int,int> f(long long x){
	map<int, int> v;
	for(int i=2; i<=x; i++){
		auto fact = prime_factorization(i);
		for(int j=0; j<fact.size(); j++){
			v[fact[j].first] += fact[j].second;
		}
	}
	return v;
}

long long mypow(long long x, long long y, long long MOD){
	long long ret=1LL;
	while(y>0LL){
		if(y&1LL) ret = (ret * x) % MOD;
		x = (x*x) % MOD;
		y >>= 1LL;
	}
	return ret;
}

int main(){

	string s;
	cin >> s;

	map<int,int> ans = f(s.size());

	vector<int> cnt(26,0);
	for(int i=0; i<s.size(); i++){
		cnt[ s[i] - 'A' ]++;
	}

	for(int i=0; i<26; i++){
		if(cnt[i] <= 1) continue;
		auto sub = f(cnt[i]);
		for(auto itr=sub.begin(); itr != sub.end(); itr++){
			ans[itr->first] -= itr->second;
		}
	}

	long long ret = 1;
	for(auto itr=ans.begin(); itr!=ans.end(); itr++){
		ret *= mypow(itr->first,itr->second,573);
		ret %= 573;
	}

	ret -= 1;
	if(ret < 0) ret += 573;
	ret %= 573;

	cout << ret << endl;
	return 0;
}
0