結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-07-13 20:16:19 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 645 ms / 1,000 ms | 
| コード長 | 819 bytes | 
| コンパイル時間 | 1,202 ms | 
| コンパイル使用メモリ | 110,536 KB | 
| 最終ジャッジ日時 | 2025-01-11 20:19:11 | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 28 | 
ソースコード
#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));
    }
}
            
            
            
        