文章目录
C题
Hakase and Nano
博弈论
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 1e6 + 10;
const int M = 2e6 + 1000;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int pi = acos(-1);
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll T, m, f, tot;
ll a[N];
void init()
{
memset(a, 0, sizeof(a));
tot = 0;
}
int main()
{
// IOS;
scanf("%lld", &T);
while (T--)
{
init();
scanf("%lld %lld", &m, &f);
for (int i = 1; i <= m; i++)
{
scanf("%lld", &a[i]);
if (a[i] == 1)
tot++;
}
if (f == 1)
{
if (tot % 3 == 0 && tot == m)
puts("No");
else
puts("Yes");
}
else
{
if ((tot == m - 1 && m % 3 == 0) || (m % 3 == 1 && tot >= m - 1))
puts("No");
else
puts("Yes");
}
}
return 0;
}
D题
Master of Random
数论
越界问题蚌埠住了,一直RE
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 1e6 + 10;
const int M = 2e6 + 1000;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int pi = acos(-1);
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll T, n, res, cnt;
ll a[N], fac[N], inv[N]; //1e8运行错误,内存会爆
ll ksm(ll a, ll b)
{
ll res = 1;
for (; b; b >>= 1)
{
if (b & 1)
res = res * a % mod; //快速幂能写错giao
a = a * a % mod;
}
return res % mod;
}
void init()
{
fac[0] = 1; //
for (ll i = 1; i < N; i++)
{
fac[i] = fac[i - 1] * i % mod;
inv[i] = ksm(i, mod - 2);
}
}
int main()
{
// IOS;
init();
scanf("%lld", &T);
while (T--)
{
scanf("%lld", &n);
for (ll i = 0; i < n; i++)
scanf("%lld", &a[i]);
cnt = fac[n - 1];
res = a[0] * fac[n - 1] % mod;
for (ll i = 1; i < n; i++)
{
cnt = (cnt + fac[n - 1] * inv[i] % mod) % mod;
res = (res + cnt * a[i] % mod) % mod;
}
res = res * ksm(fac[n], mod - 2) % mod;
// res = res *inv[fac[n]] % mod;//inv[fac[n]]会越界
printf("%lld\n", res % mod);
}
return 0;
}