結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2016-11-11 23:06:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 981 bytes |
| コンパイル時間 | 841 ms |
| コンパイル使用メモリ | 86,144 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-25 09:18:24 |
| 合計ジャッジ時間 | 1,813 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 WA * 9 |
ソースコード
#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 << 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;
}
mayoko_