結果
問題 | No.443 GCD of Permutation |
ユーザー |
![]() |
提出日時 | 2016-11-11 22:38:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 807 bytes |
コンパイル時間 | 1,391 ms |
コンパイル使用メモリ | 163,452 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-25 08:39:46 |
合計ジャッジ時間 | 2,269 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 7 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef __int128 Int; int f(string t){ sort(t.begin(),t.end()); long long w = -1; do{ long long x = atoi(t.c_str()); if( w == -1 ) w = x; w = __gcd(x,w); }while(next_permutation(t.begin(),t.end())); return w; } bool single(string s){ return s.size() == count(s.begin(),s.end(),s[0]); } int main(){ string s; cin >> s; if( single(s) ){ cout << s << endl; return 0; } if( s.size() <= 6 ){ cout << f(s) << endl; return 0; } int sum = 0; for(auto &c : s ) sum += c - '0'; int ev = 1; for(int i = 8 ; i >= 2 ; i-=2){ int f = 1; for(int j = 0 ; j < s.size() ; j++) if( (s[j] - '0') % i != 0 ){ f = 0; } if(f){ ev = i; break; } } int od = sum % 9 == 0 ? 9 : sum % 3 == 0 ? 3 : 1; cout << od * ev << endl; }