結果

問題 No.171 スワップ文字列(Med)
ユーザー ayame_pyayame_py
提出日時 2016-02-10 14:31:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 168,464 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 20:40:04
合計ジャッジ時間 2,171 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

int a=191,b=3;

ll mod_pow(ll n, ll m, int modulo){
    if (m==1) return n;
    ll tmp = mod_pow(n,m/2,modulo);
    tmp*=tmp;
    tmp%=modulo;
    if (m%2==0) return tmp;
    tmp*=n;
    tmp%=modulo;
    return tmp;
}

string s;
int alpha[26];

int main(){
    ios::sync_with_stdio(false);
    cin >> s;
    REP(i,s.length()) alpha[s[i]-'A']++;
    int ans_a=1,ans_b=1;
    FOR(i,2,s.length()+1){
        ans_a*=i;ans_a%=a;
        ans_b*=i;ans_b%=b;
    }
    REP(i,26){
        int tmp_a=1,tmp_b=1;
        FOR(j,2,alpha[i]+1){
            tmp_a*=j;tmp_a%=a;
            tmp_b*=j;tmp_b%=b;
        }
        if(ans_a==tmp_a) ans_a=1;
        else ans_a*=mod_pow(tmp_a, a-2, a);ans_a%=a;
        if(ans_b==tmp_b) ans_b=1;
        else ans_b*=tmp_b;ans_b%=b;
    }
    
    ans_a+=a-1;ans_a%=a;
    ans_b+=b-1;ans_b%=b;
    
    map<int,int> ans;
    REP(i,a){
        ans[ans_b+i*b]++;
    }
    REP(i,b) if(ans[ans_a+i*a]) cout << ans_a+i*a << endl;
    return 0;
}
0