QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863650 | #9870. Items | liyelin | WA | 741ms | 10920kb | C++14 | 6.2kb | 2025-01-19 20:45:45 | 2025-01-19 20:45:47 |
Judging History
answer
#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define ROF(i, r, l) for (int i = (r); i >= (l); --i)
#define popc(x) __builtin_popcount(x)
#define allc(x) (x).begin(), (x).end()
#define SZ(v) (int)v.size()
#define PII pair<int, int>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
bool Mbe;
template <typename A, typename B>
void chkmax(A &a, B b) {
a = a > b ? a : b;
}
template <typename A, typename B>
void chkmin(A &a, B b) {
a = a < b ? a : b;
}
namespace lyl {
template<int MOD> struct modint {
int val;
constexpr modint(int v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; }
constexpr int getmod() const { return MOD; }
constexpr modint operator - () const noexcept { return val ? MOD - val : 0; }
constexpr modint operator + (const modint &r) const noexcept { return modint(*this) += r; }
constexpr modint operator - (const modint &r) const noexcept { return modint(*this) -= r; }
constexpr modint operator * (const modint &r) const noexcept { return modint(*this) *= r; }
constexpr modint operator / (const modint &r) const noexcept { return modint(*this) /= r; }
constexpr modint &operator += (const modint &r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr modint &operator -= (const modint &r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr modint &operator *= (const modint &r) noexcept {
val = 1ll * val * r.val % MOD;
return *this;
}
constexpr modint &operator /= (const modint &r) noexcept {
int a = r.val, b = MOD, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b, swap(a, b);
u -= t * v, swap(u, v);
}
val = 1ll * val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator < (const modint &r) const noexcept { return this->val < r.val; }
constexpr bool operator == (const modint &r) const noexcept { return this->val == r.val; }
constexpr bool operator != (const modint &r) const noexcept { return this->val != r.val; }
friend constexpr istream &operator >> (istream &is, modint<MOD> &x) noexcept {
is >> x.val;
x.val %= MOD;
if (x.val < 0) x.val += MOD;
return is;
}
friend constexpr ostream &operator << (ostream &os, const modint<MOD> &x) noexcept { return os << x.val; }
friend constexpr modint<MOD> modpow(const modint<MOD> &r, ll n) noexcept {
if (n == 0) return 1;
if (n < 0) return modpow(modinv(r), -n);
auto t = modpow(r, n / 2);
t = t * t;
if (n & 1) t = t * r;
return t;
}
friend constexpr modint<MOD> modinv(const modint<MOD> &r) noexcept {
int a = r.val, b = MOD, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b, swap(a, b);
u -= t * v, swap(u, v);
}
return modint<MOD>(u);
}
};
const int mod = 998244353;
using Z = modint<mod>;
const int N = 4e5 + 5;
const Z G = 3;
const Z Gi = (mod + 1) / 3;
int n, a[N], rev[N];
ll m;
void change(Z *f, int n) {
FOR (i, 0, n - 1) {
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (n >> 1));
if (i < rev[i]) {
swap(f[i], f[rev[i]]);
}
}
}
void NTT(Z *f, int n, int inv) {
change(f, n);
for (int k = 2; k <= n; k <<= 1) {
Z wn = modpow(inv == -1 ? Gi : G, (mod - 1) / k);
for (int i = 0; i < n; i += k) {
Z w = 1;
for (int p = i * k; p < i * k + k / 2; ++p) {
Z x = f[p], y = w * f[p + k / 2];
f[p] = x + y;
f[p + k / 2] = x - y;
w *= wn;
}
}
}
if (inv == -1) {
Z t = modinv((Z)n);
FOR (i, 0, n - 1) {
f[i] *= t;
}
}
}
void mul(Z *f, Z *g, int len) {
NTT(f, 1, len);
NTT(g, 1, len);
FOR (i, 0, len - 1) {
f[i] *= g[i];
}
NTT(f, -1, len);
FOR (i, 2 * n + 1, len) {
f[i] = 0;
}
}
Z ans[N], tmp[N];
void ksm(Z *f, int n, int k) {
int len = 1;
while (len < n) {
len <<= 1;
}
memcpy(ans, f, sizeof(ans));
--k;
while (k) {
if (k & 1) {
memcpy(tmp, f, sizeof(tmp));
mul(ans, tmp, len);
}
k >>= 1;
memcpy(tmp, f, sizeof(tmp));
mul(f, tmp, len);
}
}
Z F[N];
void solve() {
memset(F, 0, sizeof(F));
memset(ans, 0, sizeof(ans));
cin >> n >> m;
FOR (i, 1, n) {
cin >> a[i];
}
ll d = m / n;
FOR (i, 1, n) {
a[i] -= d;
}
m -= d * n;
F[0] += 1;
FOR (i, 1, n) {
a[i] += n;
F[a[i]] += 1;
}
// FOR (i, 0, n << 1) {
// cout << F[i] << ' ';
// }
// cout << '\n';
ksm(F, n << 1 | 1, n);
if (ans[n + m] != 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
bool Meb;
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
lyl::solve();
}
// cerr << "Space: " << abs(&Meb - &Mbe) / 1024.0 / 1024.0 << "MB\n";
// cerr << "Time: " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 10920kb
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: -100
Wrong Answer
time: 741ms
memory: 10144kb
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 Yes Yes No Yes No No Yes No Yes Yes Yes No Yes No No No Yes No No Yes Yes Yes Yes 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...
result:
wrong answer expected NO, found YES [18th token]