結果
| 問題 | 
                            No.171 スワップ文字列(Med)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             koyumeishi
                         | 
                    
| 提出日時 | 2015-03-22 23:49:51 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 1,000 ms | 
| コード長 | 1,467 bytes | 
| コンパイル時間 | 756 ms | 
| コンパイル使用メモリ | 89,288 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-29 00:15:47 | 
| 合計ジャッジ時間 | 1,285 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 | 
ソースコード
#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;
}
            
            
            
        
            
koyumeishi