結果

問題 No.443 GCD of Permutation
ユーザー mayoko_mayoko_
提出日時 2016-11-11 23:09:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 86,188 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-04 03:04:26
合計ジャッジ時間 1,434 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 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 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	string N;
	cin >> N;
	int n = N.size();
	sort(N.begin(), N.end());
	if (N[0] == N[n-1]) {
		cout << N << endl;
		return 0;
	}
	if (N[n-2] == 0) {
		cout << N[n-1] << endl;
		return 0;
	}
	int sum = 0;
	int cnt0 = 0, cnt2 = 0, cnt4 = 0, cnt8 = 0;
	for (char c : N) {
		int num = c-'0';
		sum += num;
		if (num == 0) ++cnt0;
		else {
			if (num%2 == 0) ++cnt2;
			if (num%4 == 0) ++cnt4;
			if (num%8 == 0) ++cnt8;
		}
	}
	int ans = 1;
	if (sum%9 == 0) ans *= 9;
	else if (sum%3 == 0) ans *= 3;
	if (cnt8 >= 2 && cnt8 + cnt0 == n) ans *= 8;
	else if (cnt4 >= 2 && cnt4 + cnt0 == n) ans *= 4;
	else if (cnt2 > 0 && cnt2 + cnt0 == n) ans *= 2;
	cout << ans << endl;
	return 0;
}
0