結果

問題 No.443 GCD of Permutation
ユーザー ytqm3ytqm3
提出日時 2022-04-07 14:14:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 6,124 ms
コンパイル使用メモリ 200,268 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 17:32:39
合計ジャッジ時間 4,438 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  string S;
  cin>>S;
  int N=S.size();
  vector<int> cnt(10);
  for(int i=0;i<N;++i){
    cnt[S[i]-'0']++;
  }
  for(int i=0;i<10;++i){
    if(cnt[i]==N){
      cout<<S<<endl;
      return 0;
    }
  }
  int ans=1;
  for(int i=2;i<=9;++i){
    int sm=0;
    for(int j=0;j<10;j+=i){
      sm+=cnt[j];
    }
    if(sm==N){
      ans=lcm(ans,i);
    }
  }
  int dsm=0;
  for(int i=0;i<10;++i){
    dsm+=i*cnt[i];
  }
  if(dsm%9==0){
    ans=lcm(ans,9);
  }
  if(dsm%3==0){
    ans=lcm(ans,3);
  }
  cout<<ans<<endl;
}
0