結果
| 問題 | No.443 GCD of Permutation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-20 21:54:05 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 655 bytes |
| 記録 | |
| コンパイル時間 | 3,158 ms |
| コンパイル使用メモリ | 175,904 KB |
| 実行使用メモリ | 9,908 KB |
| 最終ジャッジ日時 | 2026-10-20 21:55:00 |
| 合計ジャッジ時間 | 4,007 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 9 |
ソースコード
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
int main() {
using namespace std;
auto perm_gcd = [&](string s) -> string {
int n = s.size();
sort(s.begin(), s.end());
if (s[0] == s[n - 1]) { return s; }
int g = s[n - 1] - '0', tot = 0;
for (char c : s) {
g = gcd(g, c - '0');
tot = (tot + c - '0') % 9;
}
if (tot % 3 > 0) { return to_string(g); }
if (tot > 0) { return to_string(g * 3); }
if (g < 9) { return to_string(g * 9); }
return "9";
};
string s;
cin >> s;
cout << perm_gcd(s) << endl;
}