結果

問題 No.443 GCD of Permutation
ユーザー KKT89KKT89
提出日時 2020-07-13 20:16:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 629 ms / 1,000 ms
コード長 819 bytes
コンパイル時間 1,111 ms
コンパイル使用メモリ 114,940 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-11 15:32:01
合計ジャッジ時間 4,677 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 30 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 13 ms
6,676 KB
testcase_18 AC 444 ms
6,676 KB
testcase_19 AC 20 ms
6,676 KB
testcase_20 AC 442 ms
6,676 KB
testcase_21 AC 60 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 53 ms
6,676 KB
testcase_26 AC 47 ms
6,676 KB
testcase_27 AC 31 ms
6,676 KB
testcase_28 AC 56 ms
6,676 KB
testcase_29 AC 56 ms
6,676 KB
testcase_30 AC 59 ms
6,676 KB
testcase_31 AC 629 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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{
        int n=s.size();
        int g=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                g=__gcd(g,abs((s[i]-'0')-(s[j]-'0')));
            }
        }
        g*=9;
        int d=0;
        for(char c:t){
            d=(d*10+(c-'0'))%g;
        }
        printf("%d\n",__gcd(g,d));
    }
}
0