結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  tubo28 | 
| 提出日時 | 2016-11-11 22:41:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 715 bytes | 
| コンパイル時間 | 1,523 ms | 
| コンパイル使用メモリ | 167,316 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-25 08:41:00 | 
| 合計ジャッジ時間 | 2,461 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 23 WA * 5 | 
ソースコード
#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
int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(count(all(s), s[0]) == n){
        cout << s << 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;
    }
}
            
            
            
        