QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#813834 | #9870. Items | wangjunrui | RE | 120ms | 3820kb | C++14 | 3.0kb | 2024-12-14 12:59:00 | 2024-12-14 12:59:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 4e5 + 5;
constexpr int mod = 998244353;
constexpr inline ll quickpow(ll a, int b = mod - 2)
{
ll res = 1;
while (b)
{
if (b & 1)
(res *= a) %= mod;
(a *= a) %= mod;
b >>= 1;
}
return res;
}
constexpr int inv3 = quickpow(3, mod - 2);
int limit, len, rk[N];
inline void init(int n)
{
len = 0;
limit = 1;
while (limit < n)
{
limit <<= 1;
++len;
}
for (int i = 0; i < limit; ++i)
rk[i] = (rk[i >> 1] >> 1) | ((i & 1) << (len - 1));
}
struct poly
{
vector<ll> dp;
poly(int _n = 0)
{
dp.resize(_n);
}
inline int size()
{
return (int)dp.size();
}
inline void resize(int n)
{
dp.resize(n);
}
template <typename T>
inline ll operator [](const T &x) const
{
return dp[x];
}
template <typename T>
inline ll &operator [](const T &x)
{
return dp[x];
}
inline void NTT()
{
for (int i = 0; i < limit; ++i)
if (i < rk[i])
swap(dp[i], dp[rk[i]]);
for (int mid = 1; mid < limit; mid <<= 1)
{
ll gn = quickpow(3, (mod - 1) / (mid << 1));
for (int i = 0; i < limit; i += mid << 1)
{
ll g = 1;
for (int j = 0; j < mid; ++j, (g *= gn) %= mod)
{
ll x = dp[i + j], y = dp[i + j + mid] * g % mod;
dp[i + j] = (x + y) % mod;
dp[i + j + mid] = (x - y) % mod;
}
}
}
}
inline void INTT()
{
for (int i = 0; i < limit; ++i)
if (i < rk[i])
swap(dp[i], dp[rk[i]]);
for (int mid = 1; mid < limit; mid <<= 1)
{
ll gn = quickpow(inv3, (mod - 1) / (mid << 1));
for (int i = 0; i < limit; i += mid << 1)
{
ll g = 1;
for (int j = 0; j < mid; ++j, (g *= gn) %= mod)
{
ll x = dp[i + j], y = dp[i + j + mid] * g % mod;
dp[i + j] = (x + y) % mod;
dp[i + j + mid] = (x - y) % mod;
}
}
}
ll inv = quickpow(limit);
for (int i = 0; i < limit; ++i)
(dp[i] *= inv) %= mod;
}
inline friend auto operator*(poly lhs, poly rhs)
{
int up = lhs.size() + rhs.size() - 1;
init(up);
poly res(limit);
lhs.resize(limit), rhs.resize(limit);
lhs.NTT(), rhs.NTT();
for (int i = 0; i < limit; ++i)
res[i] = lhs[i] * rhs[i] % mod;
res.INTT();
res.resize(up);
return res;
}
inline void update(int x)
{
dp.erase(dp.begin(), dp.begin() + x);
dp.erase(dp.end() - x, dp.end());
}
inline void print()
{
for (auto x : dp)
cout << (x + mod) % mod << ' ';
cout << '\n';
}
};
inline void _main()
{
int n;
ll m;
cin >> n >> m;
poly res(2 * n + 1), f(2 * n + 1);
for (int i = 0; i < n; ++i)
{
int x;
cin >> x;
f[x + n - m / n] = 1;
}
res[n] = 1;
for (int i = 0; (1 << i) <= n; ++i)
{
if ((n >> i) & 1)
{
res = res * f;
res.update(n);
}
f = f * f;
f.update(n);
}
if (res[m % n + n])
cout << "Yes\n";
else
cout << "No\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int test = 1;
cin >> test;
while (test--)
_main();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
input:
4 5 25 0 0 0 0 5 5 11 4 4 4 5 5 5 0 1 2 3 4 5 5 25 0 1 2 3 4
output:
Yes No No No
result:
ok 4 token(s): yes count is 1, no count is 3
Test #2:
score: 0
Accepted
time: 13ms
memory: 3628kb
input:
1314 1 0 0 1 0 1 1 1 0 1 1 1 2 0 0 0 2 0 0 1 2 0 0 2 2 0 1 0 2 0 1 1 2 0 1 2 2 0 2 0 2 0 2 1 2 0 2 2 2 1 0 0 2 1 0 1 2 1 0 2 2 1 1 0 2 1 1 1 2 1 1 2 2 1 2 0 2 1 2 1 2 1 2 2 2 2 0 0 2 2 0 1 2 2 0 2 2 2 1 0 2 2 1 1 2 2 1 2 2 2 2 0 2 2 2 1 2 2 2 2 2 3 0 0 2 3 0 1 2 3 0 2 2 3 1 0 2 3 1 1 2 3 1 2 2 3 2 0...
output:
Yes No No Yes Yes Yes Yes Yes No No Yes No No No Yes No Yes No No No No No No Yes Yes Yes Yes Yes Yes Yes No No No No No No Yes No Yes No No No Yes No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No Yes No No No Yes No No No Yes Yes Yes...
result:
ok 1314 token(s): yes count is 732, no count is 582
Test #3:
score: 0
Accepted
time: 120ms
memory: 3568kb
input:
10000 4 1 0 0 0 0 4 1 0 0 0 1 4 1 0 0 0 2 4 1 0 0 0 3 4 1 0 0 0 4 4 1 0 0 1 0 4 1 0 0 1 1 4 1 0 0 1 2 4 1 0 0 1 3 4 1 0 0 1 4 4 1 0 0 2 0 4 1 0 0 2 1 4 1 0 0 2 2 4 1 0 0 2 3 4 1 0 0 2 4 4 1 0 0 3 0 4 1 0 0 3 1 4 1 0 0 3 2 4 1 0 0 3 3 4 1 0 0 3 4 4 1 0 0 4 0 4 1 0 0 4 1 4 1 0 0 4 2 4 1 0 0 4 3 4 1 0 ...
output:
No Yes No No No Yes Yes Yes Yes Yes No Yes No No No No Yes No No No No Yes No No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes No No No Yes Yes Yes Yes Yes No Yes No No No No Yes No No No No Yes No No No No Yes No No No Yes Yes Yes Yes ...
result:
ok 10000 token(s): yes count is 6168, no count is 3832
Test #4:
score: 0
Accepted
time: 25ms
memory: 3568kb
input:
1612 5 0 0 0 0 0 0 5 0 1 1 1 1 1 5 0 0 1 1 1 1 5 0 2 2 2 2 2 5 0 0 2 2 2 2 5 0 1 2 2 2 2 5 0 0 1 2 2 2 5 0 3 3 3 3 3 5 0 0 3 3 3 3 5 0 1 3 3 3 3 5 0 0 1 3 3 3 5 0 2 3 3 3 3 5 0 0 2 3 3 3 5 0 1 2 3 3 3 5 0 0 1 2 3 3 5 0 4 4 4 4 4 5 0 0 4 4 4 4 5 0 1 4 4 4 4 5 0 0 1 4 4 4 5 0 2 4 4 4 4 5 0 0 2 4 4 4 5...
output:
Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No No No Yes No No No Yes No No No Yes No No No Yes No No No Yes No No No Yes No No No...
result:
ok 1612 token(s): yes count is 864, no count is 748
Test #5:
score: 0
Accepted
time: 70ms
memory: 3820kb
input:
4662 6 0 0 0 0 0 0 0 6 0 1 1 1 1 1 1 6 0 0 1 1 1 1 1 6 0 2 2 2 2 2 2 6 0 0 2 2 2 2 2 6 0 1 2 2 2 2 2 6 0 0 1 2 2 2 2 6 0 3 3 3 3 3 3 6 0 0 3 3 3 3 3 6 0 1 3 3 3 3 3 6 0 0 1 3 3 3 3 6 0 2 3 3 3 3 3 6 0 0 2 3 3 3 3 6 0 1 2 3 3 3 3 6 0 0 1 2 3 3 3 6 0 4 4 4 4 4 4 6 0 0 4 4 4 4 4 6 0 1 4 4 4 4 4 6 0 0 1...
output:
Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No Yes No...
result:
ok 4662 token(s): yes count is 2730, no count is 1932
Test #6:
score: -100
Runtime Error
input:
1 100000 9999999999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 9...