結果

問題 No.443 GCD of Permutation
ユーザー koprickykopricky
提出日時 2017-07-17 04:46:20
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,360 bytes
コンパイル時間 1,270 ms
コンパイル使用メモリ 162,476 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 22:59:35
合計ジャッジ時間 4,147 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 AC 1 ms
5,376 KB
testcase_04 RE -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 RE -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 RE -
testcase_24 WA -
testcase_25 AC 2 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 2 ms
5,376 KB
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int gcd(int a,int b)
{
    if(a % b == 0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}

int main()
{
    string s;
    cin >> s;
    vector<int> vec((int)s.size());
    bool flag = true;
    rep(i,s.size()){
        vec[i] = (int)(s[i] - '0');
        if(i >= 1 && vec[i] != vec[i-1]){
            flag = false;
        }
    }
    if(flag){
        cout << s << endl;
        return 0;
    }
    int sm = accumulate(all(vec),0);
    int g=1;
    rep(i,9){
        g *= i+1;
    }
    rep(i,vec.size()){
        g = gcd(g,vec[i]);
    }
    if(sm % 9 == 0){
        cout << g * 9 / gcd(g,9) << endl;
    }else if(sm % 3 == 0){
        cout << g * 3 / gcd(g,3) << endl;
    }else{
        cout << g << endl;
    }
    return 0;
}
0