結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2025-01-27 17:49:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,031 bytes |
コンパイル時間 | 2,480 ms |
コンパイル使用メモリ | 197,144 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-27 17:49:16 |
合計ジャッジ時間 | 4,063 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 WA * 11 |
ソースコード
#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(); sort(all(s)); if(n<10){ int ans=0; do ans=__gcd(ans,stoll(s));while(next_permutation(all(s))); cout<<ans<<endl; return; } if(s.front()==s.back()){ cout<<s<<endl; return; } if(s[n-2]=='0'){ cout<<s.back()<<endl; return; } int sum=0,cnt0=0,cnt2=0,cnt4=0,cnt8=0; for(auto c:s){ int x=c-'0'; sum+=x; if(!c)cnt0++; if(c&&!c%2)cnt2++; if(c&&!c%4)cnt4++; if(c&&!c%8)cnt8++; } int ans=1; //2 if(cnt2&&cnt2+cnt0==n)ans*=2; if(cnt4&&cnt4+cnt0==n)ans*=2; if(cnt8&&cnt8+cnt0==n)ans*=2; //3 if(!sum%3)ans*=3; if(!sum%9)ans*=3; cout<<ans<<endl; } } signed main(){ int t=1; //cin>>t; while(t--)AC::solve(); }