結果

問題 No.171 スワップ文字列(Med)
ユーザー 青林青林
提出日時 2023-02-06 01:57:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 1,000 ms
コード長 678 bytes
コンパイル時間 2,358 ms
コンパイル使用メモリ 197,988 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 15:15:32
合計ジャッジ時間 3,300 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MOD=573;
char s[1010];
int a[30],m[1010],d[1010],cnt;
int gcd(int p,int q){
    int r;
    while(q){
        r=p%q; p=q; q=r;
    }
    return p;
}
int main(){
    cin>>s;
    int len=strlen(s);
    for(int i=0;i<len;++i){
        ++a[s[i]-'A'];
        m[i]=i+1;
    }
    for(int i=0;i<26;++i)
        for(int j=2;j<=a[i];++j)
            d[cnt++]=j;
    for(int i=0;i<cnt;++i)
        for(int j=0;j<len;++j){
            int g=gcd(d[i],m[j]);
            d[i]/=g;
            m[j]/=g;
        }
    int ans=1;
    for(int i=1;i<len;++i)
        ans=ans*m[i]%MOD;
    if(ans==0) ans=MOD;
    cout<<ans-1;
    return 0;
}
0