提出 #67790457
ソースコード 拡げる
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops,inline")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=3e18;
ll fpow(ll a,ll b,ll m)
{
if(!b) return 1;
ll tmp=1;
for(ll cur=a;b;b>>=1,cur=cur*cur%m) if(b&1) tmp=tmp*cur%m;
return tmp;
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
const int N=2e5+5;
bool vis[N];
int R[N];
int a[N];
map<vector<int>,pii> dp;
pii calc(vector<int> a)
{
unisort(a);
reverse(a.begin(),a.end());
while(!a.empty()&&a.back()<=1) a.pop_back();
if(a.empty()) return {1,1};
if(a.size()==1) return {R[a[0]],1};
if(a.size()<=100&&dp.count(a)) return dp[a];
vector<int> b(a.begin(),a.end()-1);
int x=a.back();
pii res=calc(b);
rep(i,b.size()) b[i]=__gcd(b[i],x);
pii tmp=calc(b);
res.F=1LL*res.F*R[x]%MOD2*tmp.S%MOD2;
res.S=1LL*res.S*tmp.F%MOD2;
if(a.size()<=100) dp[a]=res;
return res;
}
void solve()
{
int n;
cin>>n;
rep1(i,n) cin>>a[i];
int ans=1;
vector<int> b;
rep1(i,n)
{
bool found=0;
for(int j=a[i];j<N;j+=a[i]) if(vis[j])
{
found=1;
break;
}
if(!found)
{
vector<int> c=b;
rep(j,c.size()) c[j]=__gcd(c[j],a[i]);
pii tmp=calc(c);
ans=1LL*ans*R[a[i]]%MOD2*tmp.S%MOD2*inv(tmp.F,MOD2)%MOD2;
b.pb(a[i]);
}
vis[a[i]]=1;
cout<<ans<<"\n";
}
}
signed main()
{
MottoHayaku
int cur=1;
rep1(i,N-1)
{
R[i]=(R[i-1]+cur)%MOD2;
cur=1LL*cur*10%MOD2;
}
int t;
//cin>>t;
t=1;
while(t--)
{
solve();
}
}
提出情報
| 提出日時 |
|
| 問題 |
C - Repunits |
| ユーザ |
Fysty |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
0 |
| コード長 |
2667 Byte |
| 結果 |
TLE |
| 実行時間 |
2211 ms |
| メモリ |
17352 KiB |
コンパイルエラー
Main.cpp: In function ‘pii calc(std::vector<int>)’:
Main.cpp:33:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
33 | #define rep(i,n) for(int i=0;i<n;i++)
| ^
Main.cpp:60:5: note: in expansion of macro ‘rep’
60 | rep(i,b.size()) b[i]=__gcd(b[i],x);
| ^~~
Main.cpp: In function ‘void solve()’:
Main.cpp:33:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
33 | #define rep(i,n) for(int i=0;i<n;i++)
| ^
Main.cpp:87:13: note: in expansion of macro ‘rep’
87 | rep(j,c.size()) c[j]=__gcd(c[j],a[i]);
| ^~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
0 / 900 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 03_hcn_00.txt, 03_hcn_01.txt, 03_hcn_02.txt, 03_hcn_03.txt, 03_hcn_04.txt, 04_max_00.txt, 05_min_00.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
2 ms |
4272 KiB |
| 00_sample_01.txt |
AC |
2 ms |
4124 KiB |
| 00_sample_02.txt |
AC |
2 ms |
4300 KiB |
| 01_n_small_00.txt |
AC |
103 ms |
6052 KiB |
| 01_n_small_01.txt |
AC |
13 ms |
4880 KiB |
| 01_n_small_02.txt |
AC |
29 ms |
5048 KiB |
| 01_n_small_03.txt |
AC |
118 ms |
6128 KiB |
| 01_n_small_04.txt |
AC |
59 ms |
5560 KiB |
| 02_random_00.txt |
TLE |
2208 ms |
15464 KiB |
| 02_random_01.txt |
TLE |
2211 ms |
15196 KiB |
| 02_random_02.txt |
TLE |
2208 ms |
15256 KiB |
| 02_random_03.txt |
TLE |
2208 ms |
15484 KiB |
| 02_random_04.txt |
TLE |
2208 ms |
15344 KiB |
| 02_random_05.txt |
TLE |
2208 ms |
15532 KiB |
| 02_random_06.txt |
TLE |
2208 ms |
15600 KiB |
| 02_random_07.txt |
TLE |
2208 ms |
15596 KiB |
| 02_random_08.txt |
TLE |
2208 ms |
15048 KiB |
| 02_random_09.txt |
TLE |
2208 ms |
15440 KiB |
| 02_random_10.txt |
TLE |
2208 ms |
17352 KiB |
| 02_random_11.txt |
TLE |
2208 ms |
15096 KiB |
| 02_random_12.txt |
TLE |
2208 ms |
15608 KiB |
| 02_random_13.txt |
TLE |
2208 ms |
15304 KiB |
| 02_random_14.txt |
TLE |
2208 ms |
15344 KiB |
| 03_hcn_00.txt |
TLE |
2208 ms |
15216 KiB |
| 03_hcn_01.txt |
TLE |
2208 ms |
15020 KiB |
| 03_hcn_02.txt |
TLE |
2208 ms |
14696 KiB |
| 03_hcn_03.txt |
TLE |
2208 ms |
15304 KiB |
| 03_hcn_04.txt |
TLE |
2208 ms |
15284 KiB |
| 04_max_00.txt |
AC |
22 ms |
5060 KiB |
| 05_min_00.txt |
AC |
2 ms |
4280 KiB |