結果

問題 No.443 GCD of Permutation
ユーザー kurenai3110kurenai3110
提出日時 2016-11-12 00:05:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,126 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 63,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-16 20:26:42
合計ジャッジ時間 1,636 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	while (a) {
		b %= a;
		swap(a, b);
	}
	return b;
}

bool X[10];
bool Y[10];
int main()
{
	for (int i = 1; i < 10; i++)Y[i] = true;
	string s; cin >> s;

	vector<int> e(s.size());
	for (int i = 0; i < s.size(); i++) {
		e[i] = s[i] - '0';
	}

	int sum = 0;
	for (int i = 0; i < e.size(); i++) {
		if (e[i] % 2)Y[2] = false;
		X[e[i]] = true;
		sum += e[i];
	}
	int cnt = 0;
	for (int i = 0; i < 10; i++) {
		if (X[i])cnt++;
	}
	if (cnt == 1) {
		cout << s << endl;
		return 0;
	}
	else if (cnt ==2 && X[0]) {
		for (int i = 1; i < 10; i++)if (X[i]) {
			cout << i << endl;
			return 0;
		}
	}

	if (sum % 3)Y[3] = false;
	if (sum % 9)Y[9] = false;

	if (!Y[2]) {
		Y[4] = false;
		Y[6] = false;
		Y[8] = false;
	}
	else {
		if (X[2] || X[6]) Y[4] = false;
		if (!Y[3]) Y[6] = false;
	}

	Y[5] = false;
	Y[7] = false;
	Y[8] = false;

	int ans = 1;
	for (int i = 9; i > 0; i--) {
		if (Y[i]) {
			int a = gcd(ans,i);
			ans *= i;
			ans /= a;
		}
	}

	cout << ans << endl;

    return 0;
}
0