QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#814930 | #9870. Items | propane | WA | 7ms | 11284kb | C++20 | 4.1kb | 2024-12-14 22:53:33 | 2024-12-14 22:53:38 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;
const int maxn = 2e6 + 5, mod = 998244353, G = 3, Gi = 332748118;
int qpow(int a, int b, int mod){
int res = 1;
while (b){
if (b & 1) res = 1LL * res * a % mod;
a = 1LL * a * a % mod;
b >>= 1;
}
return res;
}
inline int mul(int a, int b){
return 1LL * a * b % mod;
}
inline void add(int &a, int b){
a += b;
if (a >= mod) a -= mod;
}
inline void sub(int &a, int b){
a -= b;
if (a < 0) a += mod;
}
int inv[(1 << 21) + 5], fact[(1 << 21) + 5], invfact[(1 << 21) + 5];
void init(int n){
inv[1] = 1;
for(int i = 2; i <= n; i++)
inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
fact[0] = invfact[0] = 1;
for(int i = 1; i <= n; i++)
fact[i] = mul(fact[i - 1], i);
invfact[n] = qpow(fact[n], mod - 2, mod);
for(int i = n - 1; i >= 1; i--)
invfact[i] = mul(invfact[i + 1], i + 1);
}
int C(int a, int b){
if (a < 0 || b < 0 || a < b) return 0;
return mul(mul(fact[a], invfact[b]), invfact[a - b]);
}
namespace NTT{
vector<int> Omega(int L){
int wn = qpow(G, mod / L, mod);
vector<int> w(L);
w[L >> 1] = 1;
for(int i = L / 2 + 1; i < L; i++) w[i] = mul(w[i - 1], wn);
for(int i = L / 2 - 1; i >= 1; i--) w[i] = w[i << 1];
return w;
}
auto W = Omega(1 << 21);
void DIF(int *a, int n) {
for(int k = n >> 1; k; k >>= 1)
for(int i = 0, y; i < n; i += k << 1)
for(int j = 0; j < k; j++){
y = a[i + j + k], a[i + j + k] = mul(a[i + j] - y + mod, W[k + j]),
add(a[i + j], y);
}
}
void IDIT(int *a, int n) {
for (int k = 1; k < n; k <<= 1)
for (int i = 0, x, y; i < n; i += k << 1)
for(int j = 0; j < k; j++){
x = a[i + j], y = mul(a[i + j + k], W[k + j]),
a[i + j + k] = x - y < 0 ? x - y + mod : x - y;
add(a[i + j], y);
}
int inv = mod - (mod - 1) / n;
for(int i = 0; i < n; i++) a[i] = mul(a[i], inv);
reverse(a + 1, a + n);
}
}
using Poly = std::vector<int>;
void DFT(Poly &a){
NTT::DIF(a.data(), a.size());
}
void IDFT(Poly &a){
NTT::IDIT(a.data(), a.size());
}
int normed(int n) {
return n == 1 ? 1 : (1 << (32 - __builtin_clz(n - 1)));
}
void norm(Poly &a) {
if (!a.empty()) a.resize(normed((int)a.size()), 0);
}
void dot(Poly &a, Poly &b) {
for(int i = 0; i < a.size(); i++)
a[i] = mul(a[i], b[i]);
}
Poly operator*(Poly a, Poly b) {
int n = a.size() + b.size() - 1, L = normed(n);
if (a.size() <= 8 || b.size() <= 8) {
Poly c(n);
for(int i = 0; i < a.size(); i++)
for(int j = 0; j < b.size(); j++)
c[i + j] = (c[i + j] + 1LL * a[i] * b[j]) % mod;
return c;
}
a.resize(L), b.resize(L);
DFT(a), DFT(b), dot(a, b), IDFT(a);
return a.resize(n), a;
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n; LL m;
cin >> n >> m;
int k = m / n;
Poly a(2 * n + 1);
for(int i = 0; i < n; i++){
int x;
cin >> x;
a[n + x - k] = 1;
}
vector<int> ans(2 * n + 1);
ans[n] = 1;
int power = n;
while(power){
if (power & 1){
auto c = ans * a;
for(int i = -n; i <= n; i++){
ans[i + n] = (c[2 * n + i] != 0);
}
}
power >>= 1;
auto c = a * a;
for(int i = -n; i <= n; i++){
ans[i + n] = (c[2 * n + i] != 0);
}
}
cout << (ans[n + m % n] ? "Yes" : "No") << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 11176kb
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: 6ms
memory: 11284kb
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:
wrong answer expected NO, found YES [199th token]