結果

問題 No.443 GCD of Permutation
ユーザー DarseinDarsein
提出日時 2016-11-17 17:59:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 810 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 152,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-04 02:56:47
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

bool isDiv(string s, int d){
  int cur = 0;
  rep(i,s.size()){
    cur = cur * 10 + (int)(s[i]-'0');
    while( cur >= d ) cur -= d;
  }
  return cur == 0;
}

int main(){
  string s;
  cin >> s;
  int l = s.size();

  vector<int> occ_d;
  rep(i,l) occ_d.emplace_back( s[i]-'0' );
  sort(occ_d.begin(), occ_d.end());
  occ_d.erase( unique(occ_d.begin(), occ_d.end()), occ_d.end() );

  if(occ_d.size() == 1){
    cout << s << endl;
    return 0;
  }

  int gcd = 0;
  for(int a : occ_d){
    for(int b : occ_d){
      int dif = abs(9*a - 9*b);
      gcd = __gcd(gcd, dif);
    }
  }

  int ans = 1;
  for(int i=gcd;i>=1;i--){
    if(gcd%i == 0 and isDiv(s, i)){
      ans = i; break;
    }
  }

  cout << ans << endl;
}
0