Codeforces - Beautiful Mirrors

E. Beautiful Mirrors

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output

Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror “Am I beautiful?”. The i-th mirror will tell Creatnx that he is beautiful with probability pi100 for all 1≤i≤n.

Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there are two possibilities:

The i-th mirror tells Creatnx that he is beautiful. In this case, if i=n Creatnx will stop and become happy, otherwise he will continue asking the i+1-th mirror next day;
In the other case, Creatnx will feel upset. The next day, Creatnx will start asking from the 1-st mirror again.
You need to calculate the expected number of days until Creatnx becomes happy.

This number should be found by modulo 998244353. Formally, let M=998244353. It can be shown that the answer can be expressed as an irreducible fraction pq, where p and q are integers and q≢0(modM). Output the integer equal to p⋅q−1modM. In other words, output such an integer x that 0≤x<M and x⋅q≡p(modM).

Input
The first line contains one integer n (1≤n≤2⋅105) — the number of mirrors.

The second line contains n integers p1,p2,…,pn (1≤pi≤100).

Output
Print the answer modulo 998244353 in a single line.

Examples
inputCopy

1
50
outputCopy
2
inputCopy
3
10 20 50
outputCopy
112
Note
In the first test, there is only one mirror and it tells, that Creatnx is beautiful with probability 12. So, the expected number of days until Creatnx becomes happy is 2.


我们令 dp[i] 为到第i面镜子的期望天数。

所以有了下面的等式。

由于懒得打字直接看图吧:


AC代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10,mod=998244353;
int n,dp[N],p[N];
inline int qmi(int a,int b){
	int res=1;	while(b){if(b&1) res=res*a%mod; a=a*a%mod; b>>=1;}	return res;
}
inline int inv(int x){return qmi(x,mod-2);}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)	scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++)	dp[i]=(dp[i-1]+1)*100%mod*inv(p[i])%mod;
	cout<<dp[n]<<endl;
	return 0;
}
全部评论

相关推荐

怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 12:04
毕业生招你惹你了,问一个发薪日来一句别看网上乱七八糟的你看哪个工作没有固定发薪日扭头就取消了面试就问了一句公司都是这个态度吗还搞上人身攻击了...
程序员小白条:呃呃呃,都还没面试,我都不会问这么细,何况通不通过,去不去都另说,你没实力和学历的话,在外面就这样,说实话没直接已读不回就不错了,浪费时间基本上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务