結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー monnumonnu
提出日時 2021-07-30 22:03:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,489 bytes
コンパイル時間 3,965 ms
コンパイル使用メモリ 228,060 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 04:51:17
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 100000
#define MOD 1000000007
#define INF 1000000000

int gcd(int a,int b){
  while(a%b!=0){
    int tmp=a%b;
    a=b;
    b=tmp;
  }
  return b;
}

ll modpow(ll a,ll n){
  a%=MOD;
  ll ret=1;
  while(n>0){
    if((n&1)==1){
      ret=ret*a%MOD;
    }
    n>>=1;
    a=a*a%MOD;
  }
  return ret;
}
ll modinv(ll x){
  return modpow(x,MOD-2);
}


int main(){
  int N;
  cin>>N;
  vector<int> c(9);
  for(int i=0;i<9;i++){
    cin>>c[i];
  }

  if(N<=5){
    vector<int> a;
    for(int i=0;i<9;i++){
      for(int j=0;j<c[i];j++){
        a.push_back(i+1);
      }
    }
    vector<int> nums;
    do{
      int x=0;
      int res=1;
      for(int i=0;i<N;i++){
        x+=a[i]*res;
        res*=10;
      }
      nums.push_back(x);
    }while(next_permutation(a.begin(),a.end()));
    int g=nums[0];
    for(auto x:nums){
      g=gcd(x,g);
    }
    cout<<g<<endl;
    return 0;
  }
  ll sum=0;
  int cnt=0;
  for(int i=0;i<9;i++){
    sum+=((ll)i+1)*(ll)c[i];
    if(c[i]>0){
      cnt++;
    }
  }
  if(cnt!=1){
    if(sum%9==0){
      cout<<9<<endl;
    }else if(sum%3==0){
      cout<<3<<endl;
    }else{
      cout<<1<<endl;
    }
  }else{
    int k=0;
    for(int i=0;i<9;i++){
      if(c[i]>0){
        k=i+1;
      }
    }
    ll x=(modpow(10,N)-1)*modinv(9)%MOD;
    x*=(ll)k;
    x%=MOD;
    cout<<x<<endl;
  }
}
0