QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867201 | #9870. Items | dspt | WA | 0ms | 8016kb | C++23 | 2.4kb | 2025-01-23 10:49:49 | 2025-01-23 10:49:49 |
Judging History
answer
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll; typedef vector<int> vi; typedef const int ci; ci p(998244353);
int power(int x, int i) { int y(1); while (i) { if (i & 1) y = (ll)x * y % p; x = (ll)x * x % p, i >>= 1; } return y; }
int r[1 << 19];
struct poly
{
vi a; poly() {} poly(const vi v) { a = v; }
poly getl(ci n) const { vi v(a); v.resize(n); return poly(v); }
int len() const { return size(a); }
int add(ci x, ci y) { return x + y < p ? x + y : x + y - p; }
int sub(ci x, ci y) { return x >= y ? x - y : x - y + p; }
void NTT(ci n, const bool t)
{
static int f[1 << 19], w[1 << 19]; a.resize(n, 0);
for (int i(0); i < n; ++i) f[i] = a[r[i]];
for (int i(1); i < n; i <<= 1)
{
ci k(power(t ? (p + 1) / 3 : 3, (p - 1) / i >> 1)); w[0] = 1;
for (int j(1); j < i; ++j) w[j] = (ll)w[j - 1] * k % p;
for (int j(0); j < n; j += i << 1) for (int k(0); k < i; ++k)
{
ci x(f[j | k]), y((ll)f[i | j | k] * w[k] % p);
f[j | k] = add(x, y); f[i | j | k] = sub(x, y);
}
}
for (int i(0); i < n; ++i) a[i] = f[i];
}
int &operator[] (ci i) { return a[i]; }
poly operator * (const poly v) const
{
poly f(*this), g(v); int n(1); while (n <= f.len() + g.len() - 1) n <<= 1;
for (int i(0); i < n; ++i) r[i] = r[i >> 1] >> 1 | (i & 1 ? n >> 1 : 0);
f.NTT(n, false); g.NTT(n, false);
for (int i(0); i < n; ++i) f[i] = (ll)f[i] * g[i] % p;
f.NTT(n, true); ci k(power(n, p - 2));
for (int i(0); i < n; ++i) f[i] = (ll)f[i] * k % p;
return f;
}
};
int main()
{
int t; scanf("%d", &t);
while (t--)
{
int n, m; scanf("%d%d", &n, &m);
poly f, g; f.a.resize(n << 1 | 1, 0); g.a.resize(n << 1 | 1); g[n + 1] = 1;
for (int i(1), j; i <= n; ++i) scanf("%d", &j), f.a[j - m / n + n] = 1;
auto shrink = [&n](poly &b) -> void
{
b.a.resize(n << 2 | 1); poly c;
for (int i(n); i <= n * 3; ++i) c.a.push_back(b[i]);
b = c;
};
int i(n);
while (i)
{
if (i & 1) g = g * f, shrink(g);
f = f * f, shrink(f); i >>= 1;
}
puts(g.a[m % n + n] ? "Yes" : "No");
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 8016kb
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:
No No No No
result:
wrong answer expected YES, found NO [1st token]