結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー re_re0101re_re0101
提出日時 2021-07-15 20:11:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,249 bytes
コンパイル時間 3,161 ms
コンパイル使用メモリ 181,296 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:15:06
合計ジャッジ時間 4,030 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 3 ms
4,348 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 3 ms
4,348 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define eb emplace_back
#define endl '\n'
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef vector<ll> vl;
const ll MOD=1000000007LL;

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}

ll modpow(ll a, ll n,ll mod=MOD) {

    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//約数の列挙O(√n)
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}


ll A_mod_B_Problem(ll n,vl a,vl l,ll b){
    reverse(all(a)),reverse(all(l));
    ll cur=1;
    ll ans=0;
    vl two(50);
    two[0]=1;
    rep(j,49)two[j+1]=two[j]*2;
    rep(i,n){
        string s=to_string(a[i]);
        vl vec(50);
        vec[0]=a[i]%b;
        rep(j,49)vec[j+1]=vec[j]*(modpow(10,two[j]*s.size(),b)+1)%b;
        ll res=0;
        rep(j,50){
            if(bit(l[i],j)){
                res=vec[j];
                ans+=res*cur%b;
                ans%=b;
                cur*=modpow(10,two[j]*s.size(),b);
                cur%=b;
            }
        } 
    }
    return ans;
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(13);
    /*--------------------------------*/
    int n;cin>>n;
  	vector<ll>c(10);
    map<int,int>mp;
    vl a(10);

  	for(int i=1;i<=9;i++){
    	cin>>c[i];
        a[i]=i;
      	if(c[i]>0)mp[i];
    }
    int g=0;
    for(auto p:mp){
        for(auto q:mp){
            if(p.fi>=q.fi){
                g=__gcd(g,9*(p.fi-q.fi));    
            }
        }
    }
    
    
    if(g==0){
        cout<<A_mod_B_Problem(11,a,c,MOD)<<endl;
        return 0;
    }
    vector<ll>vec=divisor(g);
    int ans=0;
    for(auto x:vec){
        if(A_mod_B_Problem(11,a,c,x)==0)chmax(ans,(int)x);
    }    
    cout<<ans<<endl;

}
0