結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-01-27 18:12:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 890 bytes |
| コンパイル時間 | 2,351 ms |
| コンパイル使用メモリ | 195,912 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2025-01-27 18:12:21 |
| 合計ジャッジ時間 | 3,464 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
ソースコード
#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 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