結果

問題 No.443 GCD of Permutation
コンテスト
ユーザー himueu
提出日時 2026-10-20 21:54:05
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 655 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 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
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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