結果
問題 | No.1632 Sorting Integers (GCD of M) |
ユーザー |
![]() |
提出日時 | 2021-07-15 20:11:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 2,249 bytes |
コンパイル時間 | 1,971 ms |
コンパイル使用メモリ | 181,948 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-21 17:29:37 |
合計ジャッジ時間 | 3,567 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 59 |
ソースコード
#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;}