結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-04 11:48:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 647 bytes |
| コンパイル時間 | 560 ms |
| コンパイル使用メモリ | 64,768 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 00:09:41 |
| 合計ジャッジ時間 | 1,283 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 WA * 1 |
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main()
| ^~~~
ソースコード
#include<iostream>
using namespace std;
string s;
int cnt[10];
main()
{
cin>>s;
int N=s.size();
for(int i=0;i<N;i++)cnt[s[i]-'0']++;
bool all=false;
for(int i=0;i<10;i++)all=all||cnt[i]==N;
if(all)
{
cout<<s<<endl;
return 0;
}
int sum=0;
for(int i=0;i<10;i++)sum+=cnt[i]*i;
int ans=1;
if(sum%9==0)ans=9;
else if(sum%3==0)ans=3;
if(cnt[0]+cnt[9]==N)
{
if(cnt[9]%9==0)ans*=9;
}
if(cnt[0]+cnt[8]==N)ans*=8;
else if(cnt[0]+cnt[4]+cnt[8]==N)ans*=4;
else if(cnt[0]+cnt[2]+cnt[4]+cnt[6]+cnt[8]==N)ans*=2;
if(cnt[0]+cnt[5]==N)ans*=5;
if((cnt[0]+cnt[7]==N||cnt[1]+cnt[8]==N||cnt[2]+cnt[9]==N)&&N%3==0)ans*=7;
cout<<ans<<endl;
}