QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#865465 | #9870. Items | shung | WA | 16ms | 5968kb | C++14 | 1.7kb | 2025-01-21 19:00:04 | 2025-01-21 19:00:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=600005,mod=998244353,g=3;
inline int add(int x,int y){
return x+y>=mod?x+y-mod:x+y;
}
inline int del(int x,int y){
return x-y<0?x-y+mod:x-y;
}
inline int mypow(int x,int y){
int ans=1;
while(y){
if(y&1)ans=1ll*ans*x%mod;
y>>=1;
x=1ll*x*x%mod;
}
return ans;
}
int T,n,a[N],limit,r[N];
inline void ntt(vector<int>&A,int op){
for(int i=0;i<limit;++i)if(r[i]>i)swap(A[i],A[r[i]]);
for(int mid=1;mid<limit;mid<<=1){
int L=mid+mid;
int wn=mypow(g,(mod-1)/L);
if(op==-1)wn=mypow(wn,mod-2);
for(int i=0;i<limit;i+=L){
int w=1;
for(int j=0;j<mid;++j){
int x=A[i+j],y=1ll*w*A[i+mid+j]%mod;
A[i+j]=add(x,y),A[i+mid+j]=del(x,y);
w=1ll*w*wn%mod;
}
}
}
if(op==-1){
int inv=mypow(limit,mod-2);
for(int i=0;i<limit;++i)A[i]=1ll*A[i]*inv%mod;
}
}
inline vector<int> mul(vector<int>A,vector<int>B){
int MAX=A.size()-1+B.size()-1;
limit=1;
int l=0;
while(limit<=MAX)limit<<=1,++l;
for(int i=0;i<limit;++i)r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
while(A.size()<limit)A.push_back(0);
while(B.size()<limit)B.push_back(0);
ntt(A,1),ntt(B,1);
for(int i=0;i<limit;++i)A[i]=1ll*A[i]*B[i]%mod;
ntt(A,-1);
vector<int>C;
for(int i=n;i<=n+n+n;++i)C.push_back(A[i]);
return C;
}
int main(){
scanf("%d",&T);
long long m;
while(T--){
scanf("%d%lld",&n,&m);
vector<int>A;
for(int i=0;i<=n+n;++i)A.push_back(0);
int x;
for(int i=1;i<=n;++i){
scanf("%d",&x);
A[x-m/n+n]=1;
}
vector<int>B;
for(int i=0;i<=n+n;++i)B.push_back(0);
B[n]=1;
int nn=n;
while(nn){
if(nn&1)A=mul(A,B);
nn>>=1;
B=mul(B,B);
}
if(A[m%n+n])puts("Yes");
else puts("No");
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5964kb
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: 16ms
memory: 5968kb
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]