結果

問題 No.443 GCD of Permutation
ユーザー tubo28tubo28
提出日時 2016-11-11 23:04:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,044 bytes
コンパイル時間 2,564 ms
コンパイル使用メモリ 170,520 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-16 20:32:11
合計ジャッジ時間 4,161 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,508 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,388 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl
#define int ll

signed main(){
    string s;
    while(cin >> s){
        int n = s.size();
        if(count(all(s), s[0]) == n){
            cout << s << endl;
        } else if(s.size() <= 12){
            sort(all(s));
            ll g = 0;
            do {
                g = __gcd(g, stoll(s));
            } while(next_permutation(all(s)));
            cout << g << endl;
        } else {
            int sum = 0;
            int g = 0;
            rep(i,n){
                int x = s[i] - '0';
                g = __gcd(g, x);
                sum += x;
            }
            rep(i,n){
                s[i] = (s[i] - '0') / g + '0';
            }
            sum /= g;
            if(sum%9 == 0) g *= 9;
            else if(sum%3 == 0) g *= 3;
            else g *= 1;
            cout << g << endl;
        }
    }
}
0