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;
}
全部评论

相关推荐

重生我想学测开:嵌入式的问题,我准备入行京东外卖了
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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