結果
問題 | No.443 GCD of Permutation |
ユーザー |
|
提出日時 | 2020-07-13 20:03:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,211 bytes |
コンパイル時間 | 1,133 ms |
コンパイル使用メモリ | 114,812 KB |
最終ジャッジ日時 | 2025-01-11 20:18:37 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 WA * 11 |
ソースコード
#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();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')));}}int g=abs(v[0]);for(int y:v){g=__gcd(g,abs(y));}if(n>8)cout << g << endl;else{n=stoi(s);int res=0;for(int 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;}}}