結果

問題 No.443 GCD of Permutation
ユーザー square1001square1001
提出日時 2018-05-19 20:31:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 796 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 86,192 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 01:31:32
合計ジャッジ時間 1,544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0