結果

問題 No.171 スワップ文字列(Med)
ユーザー yuustiyuusti
提出日時 2015-03-24 18:58:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,617 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 90,844 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-11 09:57:17
合計ジャッジ時間 1,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <complex>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;

int mod_pow(long long x, long long n, long long p){
	long long res = 1 % p;
	x %= p;
	while (n){
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n /= 2;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(20);

	string s;
	cin >> s;

	int cnt[256] = {};
	for (auto c : s) cnt[c]++;

	int n = s.size();

	const int m = 573;
	vector<int> rem;
	vector<int> pf = { 3, 191 };
	for (int p : pf){
		ll x = 1;
		rep(i, 256){
			FOR(j, 1, cnt[i] + 1){
				x *= j;
				x %= p;
			}
		}
		ll y = 1;
		FOR(i, 1, n + 1) y = y*i%p;

		int k = y * mod_pow(x, p - 2, p) % p;
		if (x == y) k = 1;
		rem.push_back(k);
	}

	rep(i, m){
		if (i % pf[0] == rem[0] && i % pf[1] == rem[1]){
			cout << (i+m-1)%m << endl;
			break;
		}
	}
}
0