結果
| 問題 |
No.1632 Sorting Integers (GCD of M)
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-10-06 20:15:17 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,467 bytes |
| コンパイル時間 | 1,435 ms |
| コンパイル使用メモリ | 109,400 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-06 20:15:26 |
| 合計ジャッジ時間 | 8,958 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 WA * 16 TLE * 2 |
ソースコード
#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 = 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;
}
}
momoyuu