結果

問題 No.443 GCD of Permutation
ユーザー kurenai3110kurenai3110
提出日時 2016-11-12 00:31:26
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,280 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 64,064 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 20:33:49
合計ジャッジ時間 1,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 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 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,376 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;
	Y[5] = false;
	Y[7] = false;
	Y[8] = false;
	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]) {
			Y[i] = true;
		}
	}
	else if (cnt == 2 && s.size()%6 == 0) {
		int a=0;
		for (int i = 1; i < 10; i++)if (X[i]) {
			if (a != 0) {
				if (abs(i - a) % 7 == 0)Y[7] = true;
			}
			a = i;
		}
	}

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

	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