結果

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

ソースコード

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<int> 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 = 0;
            for(int i = 1;i<=9;i++) {
                for(int j = 0;j<c[i];j++) {
                    ans *= 10;
                    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%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