結果

問題 No.443 GCD of Permutation
ユーザー KKT89KKT89
提出日時 2020-07-13 20:04:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,208 bytes
コンパイル時間 1,195 ms
コンパイル使用メモリ 118,152 KB
実行使用メモリ 267,636 KB
最終ジャッジ日時 2024-04-25 14:42:14
合計ジャッジ時間 7,111 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s;
    t=s;
    sort(t.begin(), t.end());
    if(t[0]==t.back()){
        cout << t << endl;
    }
    else{
        ll n=s.size();
        vector<int> v;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                v.push_back(9*((s[i]-'0')-(s[j]-'0')));
            }
        }
        ll g=abs(v[0]);
        for(ll y:v){
            g=__gcd(g,abs(y));
        }
        if(n>18)cout << g << endl;
        else{
            n=stoll(s);
            ll res=0;
            for(ll i=1;i*i<=g;i++){
                if(g%i==0){
                    if(n%i==0){
                        res=max(res,i);
                    }
                    if(n%(g/i)==0){
                        res=max(res,g/i);
                    }
                }
            }
            cout << res << endl;
        }
    }
}
0