結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー momoyuu
提出日時 2024-10-06 20:16:45
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,478 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 109,972 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 20:16:48
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 49 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

#include<atcoder/modint>
using mint = atcoder::modint1000000007;
ll gcd(ll a,ll b){
    if(b) return gcd(b,a%b);
    return a;

}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    vector<ll> c(10,0);
    for(int i = 1;i<=9;i++) cin>>c[i];
    {
        int cnt = 0;
        for(int i = 1;i<=9;i++) if(c[i]!=0) cnt++;
        if(cnt==1){
            mint ans = mint(10).pow(n);
            ans--;
            ans /= 9;

            for(int i = 1;i<=9;i++) {
                if(c[i]!=0) ans *= i;
            }
            cout<<ans.val()<<endl;
            return 0;
        }
    }

    ll ans = 0;
    if(n>=8){
        ans = 1;
        {
            bool fn = true;
            for(int i = 1;i<=9;i++) if(i%2==1&&c[i]!=0) fn = false;
            if(fn) ans *= 2;
        }
        ll sum = 0;
        for(int i = 1;i<=9;i++) sum += i * c[i];

        if(sum%27==0) ans *= 27;
        else if(sum%9==0) ans *= 9;
        else if(sum%3==0) ans *= 3;

        cout<<ans<<endl;
    }else{
        vector<int> all;
        for(int i = 1;i<=9;i++) for(int j = 0;j<c[i];j++) all.push_back(i);
        sort(all.begin(),all.end());
        do{
            ll now = 0;
            for(int i:all) now = now * 10 + i;
            ans = gcd(ans,now);
        }while(next_permutation(all.begin(),all.end()));
        cout<<ans<<endl;
    }

}

0