QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867195 | #9870. Items | qojszt | RE | 0ms | 0kb | C++20 | 2.9kb | 2025-01-23 10:44:55 | 2025-01-23 10:44:56 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> poly;
constexpr int M = 998244353, g = 3;
inline constexpr int mul(int x, int y) noexcept {return static_cast<long long>(x) * y % M;}
inline constexpr int add(int x, int y) noexcept {x += y;return x >= M? x - M : x;}
inline constexpr int sub(int x, int y) noexcept {x -= y;return x < 0? x + M : x;}
inline constexpr int fpw(int x, int y) noexcept
{int ret = 1;for (; y; y >>= 1, x = mul(x, x))if (y & 1)ret = mul(ret, x);return ret;}
inline constexpr int fma(int x, int y, int z) noexcept { return (static_cast<long long>(x) * y + z) % M; }
inline void NTT(poly &a, int n, const poly &rev, bool rv = 0){
for (int i = 0; i < n; ++i)if (i > rev[i])swap(a[i], a[rev[i]]);
for (int h = 1; h < n; h <<= 1)for (int j = 0, wn = fpw(g, (M - 1) / h / 2); j < n; j += (h << 1))
for (int k = j, w = 1, x, y; k < j + h; ++k, w = mul(w, wn))
{x = a[k], y = mul(w, a[k + h]);a[k] = add(x, y);a[k + h] = sub(x, y);}
if (rv){
reverse(a.begin() + 1, a.end());
for (int i = 0, inv = fpw(n, M - 2); i < n; ++i)a[i] = mul(a[i], inv);
}
}
// void print(const poly &rf){
// for (int i : rf)clog << i << ".";
// }
inline void smul(poly &f, poly g){
//print(f);clog << "*";print(g);clog << "=" << flush;
int k = ceil(log2(max(f.size(), g.size()))) + 1; int N = 1 << k;
poly rev(N); for (int i = 1; i < N; ++i)rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (k - 1));
f.resize(N); g.resize(N); NTT(f, N, rev); NTT(g, N, rev);
for (int i = 0; i < N; ++i)f[i] = mul(f[i], g[i]); NTT(f, N, rev, 1);
//print(f);clog << endl;
}
inline void smul(poly &f){
int k = ceil(log2(f.size())) + 1; int N = 1 << k;
poly rev(N); for (int i = 1; i < N; ++i)rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (k - 1));
f.resize(N); NTT(f, N, rev); for (int i = 0; i < N; ++i)f[i] = mul(f[i], f[i]); NTT(f, N, rev, 1);
}
inline void mul(poly &a, const poly &b){if (&a == &b)smul(a);else smul(a, b);}
int n;long long m;
void work(){
cin >> n >> m;int t = m / n; m %= n;
poly pl(2 * n + 1);
for (int i = 1, x; i <= n; ++i)cin >> x, ++pl[x - t + n];
auto times = [](poly &a, const poly &b){
mul(a, b);
a.erase(a.begin(), a.begin() + n);
a.resize(2 * n + 1);
};
poly rs(2 * n + 1); rs[n] = 1;//rs = 1
//print(pl);clog << "^" << n << "=" << flush;
//clog << "{" << endl;
for (int b = n; b; b >>= 1, times(pl, pl))if (b & 1)times(rs, pl);
//clog << "}" << endl;
//print(rs);clog << endl;
cout << (rs[m + n]? "Yes" : "No") << endl;
}
int main(){
freopen(".in", "r", stdin);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
cin >> t;
while (t--)work();
clog << clock() << endl;
return 0;
}
/*
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
Yes
No
No
No
*/
详细
Test #1:
score: 0
Runtime Error
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