题解 ABC326E【Revenge of "The Salary of AtCoder Inc."】
根据期望的线性性,总工资的期望等于在每一个 处获得的工资的期望之和,而在 处获得的工资的期望 ,其中 表示掷骰子掷到 且有效的概率。
初始 ,则只有从 掷骰子掷到 时才有效,显然每一种情况掷到 的概率均为 ,因此有转移方程:
使用前缀和优化即可做到 。
// Problem: E - Revenge of "The Salary of AtCoder Inc."
// Contest: AtCoder - Panasonic Programming Contest 2023(AtCoder Beginner Contest 326)
// URL: https://atcoder.jp/contests/abc326/tasks/abc326_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x, y, z) for(ll x = (y); x <= (z); ++x)
#define per(x, y, z) for(ll x = (y); x >= (z); --x)
#define debug(format...) fprintf(stderr, format)
#define fileIO(s) do {freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);} while(false)
#define endl '\n'
using namespace std;
typedef long long ll;
mt19937 rnd(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
ll randint(ll L, ll R) {
uniform_int_distribution<ll> dist(L, R);
return dist(rnd);
}
template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}
const ll N = 3e5 + 5, mod = 998244353;
ll n, a[N], inv[N], p[N], Sp[N], ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
rep(i, 1, n) cin >> a[i];
inv[0] = inv[1] = 1;
rep(i, 2, n) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
p[0] = Sp[0] = 1;
rep(i, 1, n) {
p[i] = Sp[i - 1] * inv[n] % mod;
Sp[i] = (Sp[i - 1] + p[i]) % mod;
ans = (ans + p[i] * a[i] % mod) % mod;
}
cout << ans << endl;
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】