結果
| 問題 | 
                            No.443 GCD of Permutation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kyuridenamida
                         | 
                    
| 提出日時 | 2016-11-11 22:42:43 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 886 bytes | 
| コンパイル時間 | 1,484 ms | 
| コンパイル使用メモリ | 163,048 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-25 09:00:05 | 
| 合計ジャッジ時間 | 2,259 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 21 WA * 7 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef __int128 Int;
int f(string t){
	sort(t.begin(),t.end());
	long long w = -1;
	do{
		long long x = atoi(t.c_str());
		if( w == -1 ) w = x;
		w = __gcd(x,w);
	}while(next_permutation(t.begin(),t.end()));		
	return w;
}
bool single(string s){
	return s.size() == count(s.begin(),s.end(),s[0]);
}
int main(){
	string s;
	cin >> s;
	if( single(s) ){
		cout << s << endl;
		return 0;
	}
	if( s.size() <= 6 ){
		cout << f(s) << endl;
		return 0;
	}
	int sum = 0;
	for(auto &c : s ) sum += c - '0';
	int ev = 1;
	for(int i = 8 ; i >= 2 ; i-=2){
		int f = 1;
		for(int j = 0 ; j < s.size() ; j++)
			if( (s[j] - '0') % i != 0 ){
				f = 0;
			}
		if(f){
			ev = i;
			break;
		}
	}
	int fv = 5;
	for( auto c : s ){
		if( c != '0' and c != '5' ) fv = 1;
	}
	int od = sum % 9 == 0 ? 9 : sum % 3 == 0 ? 3 : 1;
	cout << od * ev * fv << endl;
}
            
            
            
        
            
kyuridenamida