結果

問題 No.171 スワップ文字列(Med)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-25 20:27:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 1,454 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 122,912 KB
実行使用メモリ 9,444 KB
最終ジャッジ日時 2023-08-12 10:45:44
合計ジャッジ時間 2,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
9,188 KB
testcase_01 AC 10 ms
9,268 KB
testcase_02 AC 10 ms
9,216 KB
testcase_03 AC 10 ms
9,172 KB
testcase_04 AC 10 ms
9,352 KB
testcase_05 AC 10 ms
9,272 KB
testcase_06 AC 10 ms
9,216 KB
testcase_07 AC 10 ms
9,212 KB
testcase_08 AC 10 ms
9,444 KB
testcase_09 AC 10 ms
9,224 KB
testcase_10 AC 9 ms
9,280 KB
testcase_11 AC 9 ms
9,224 KB
testcase_12 AC 10 ms
9,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <sstream>

using namespace std;

vector<long long> spf;
map<long long, long long> prime;

void osa_k(long long n){
    spf.resize(n+1);
    for (long long i=0; i<=n; i++) spf[i] = i;
    for (long long i=2; i*i<=n; i++){
        if (spf[i] == i){
            for (long long j=2; i*j <= n; j++){
                spf[i*j] = min(spf[i*j], i);
            }
        }
    }
}

map<long long, map<long long, long long>> mp;

void prime_factor(long long n){
    long long m=n;
    while(n != 1){
        prime[spf[n]]++;
        n /= spf[n];
    }
    mp[m] = prime;
}

long long mod_exp(long long b, long long e, long long m){
    if (b == 0) return 0;
    long long ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

int main(){
    osa_k(1000);

    for (int i=2; i<=1000; i++) prime_factor(i);

    long long ans=1;
    string S;
    cin >> S;
    vector<long long> cnt(26);
    for (auto x : S) cnt[x-'A']++;
    for (int i=0; i<26; i++){
        for (auto &[x, y] : mp[cnt[i]]){
            mp[S.size()][x] -= y;
        }
    }

    for (auto &[x, y] : mp[S.size()]) ans = (ans * mod_exp(x, y, 573)) % 573;
    cout << (573+ans-1)%573 << endl;

    return 0;
}
0