結果

問題 No.171 スワップ文字列(Med)
ユーザー masamasa
提出日時 2015-03-23 00:13:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,177 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 69,496 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 09:39:55
合計ジャッジ時間 1,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <list>

using namespace std;

const int MOD = 573;

int main() {
	string s;

	cin >> s;
	vector<int> alpha(26, 0);

	int n = s.size();
	char c;
	for (int i = 0; i < n; i++) {
		alpha[s[i] - 'A']++;
	}

	int exist = 0;
	for (int i = 0; i < alpha.size(); i++) {
		if (alpha[i] > 0) {
			exist++;
		}
	}

	if (exist == 1) {
		cout << 0 << endl;
		return 0;
	}

	list<int> product;
	for (int i = 2; i <= n; i++) {
		product.push_back(i);
	}

	list<int> devide;
	for (int i = 0; i < alpha.size(); i++) {
		for (int j = alpha[i]; j > 1; j--) {
			devide.push_back(j);
		}
	}

	devide.sort(greater<int>());

	for (auto itd = devide.begin(); itd != devide.end(); itd++) {
		for(auto itp = product.begin(); itp != product.end(); itp++) {
			if (*itp == *itd) {
				product.erase(itp);
				break;
			} else if (*itp %= *itd) {
				*itp /= *itd;
				product.sort();
				break;
			}
		}
	}

	int ans = 1;
	for(auto itp = product.begin(); itp != product.end(); itp++) {
		ans = (ans * *itp) % MOD;
	}

	ans = (ans + MOD - 1) % MOD;
	cout << ans << endl;
	return 0;
}
0