結果

問題 No.443 GCD of Permutation
ユーザー kmjpkmjp
提出日時 2016-11-11 23:04:43
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,122 bytes
コンパイル時間 1,383 ms
コンパイル使用メモリ 159,848 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 09:17:23
合計ジャッジ時間 2,807 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 8 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
int L;
int num[10];
int sum;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	FORR(c,S) num[c-'0']++, sum+=c-'0';
	assert(num[3]==0);
	
	FOR(i,10) {
		if(num[i]==S.size()) {
			cout<<S<<endl;
			return;
		}
	}
	
	int ma=0;
	
	for(i=1;i<=9;i++) {
		int ok=1;
		FOR(j,10) if(j%i && num[j]) ok=0;
		if(ok==0) continue;
		
		if(sum%9==0) ma=max(ma,i*9/__gcd(i,9));
		if(sum%3==0) ma=max(ma,i*3/__gcd(i,3));
		ma=max(ma,i);
	}
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0