結果
| 問題 | No.443 GCD of Permutation |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-01-27 18:10:11 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WJ
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 943 bytes |
| 記録 | |
| 最終ジャッジ日時 | 2026-06-25 04:15:08 |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
ソースコード
#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;}
template<typename T>ostream&operator<<(ostream&O,vector<T>&v){for(auto&i:v)O<<i<<' ';return O;}
namespace AC{
void solve(){
string s;
cin>>s;
int n=s.size();
vector<bool>vis(10);
for(auto i:s)vis[i-'0']=1;
int d=0;
for(int i=0;i<10;i++)for(int j=i+1;j<10;j++)if(vis[i]&&vis[j])d=__gcd(d,9*(j-i));
if(!d){
cout<<s<<endl;
return;
}
vector<bool>ans(100);
for(int i=1;i<100;i++)if(d%i==0)ans[i]=1;
for(int i=0;i<50;i++){
random_shuffle(all(s));
for(int j=1;j<100;j++)if(ans[j]){
int tmp=0;
for(int k=0;k<n;k++)tmp=(tmp*10+s[k]-'0')%j;
if(tmp^0)ans[j]=0;
}
}
for(int i=99;i>=0;i--)if(ans[i]){
cout<<i<<endl;
return;
}
}
}
signed main(){
int t=1;
//cin>>t;
while(t--)AC::solve();
}
vjudge1