結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2018-05-19 20:31:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 796 bytes |
コンパイル時間 | 658 ms |
コンパイル使用メモリ | 86,028 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-14 00:07:42 |
合計ジャッジ時間 | 1,537 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
ソースコード
#include <random> #include <string> #include <iostream> #include <algorithm> using namespace std; string s; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> s; bool same = true; for (int i = 1; i < s.size(); i++) { if (i >= 1 && s[i] != s[i - 1]) same = false; } if (same) cout << s << '\n'; else { int ret = 64 * 81 * 25 * 49; int bit = 0, cur = 0; for (int i = 0; i < s.size(); i++) { bit |= 1 << (s[i] - '0'); cur = (cur * 10 + (s[i] - '0')) % ret; } ret = gcd(ret, cur); for (int i = 0; i < 10; i++) { for (int j = i + 1; j < 10; j++) { if (((bit >> i) & 1) && ((bit >> j) & 1)) { ret = gcd(ret, (j - i) * 9); } } } cout << ret << endl; } return 0; }