QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#809403 | #9870. Items | 275307894a | WA | 4ms | 14156kb | C++14 | 5.9kb | 2024-12-11 14:50:26 | 2024-12-11 14:51:05 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=N*20+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
using poly=vector<ll>;
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
ll sgn(int x){return x&1?mod-1:1;}
namespace Poly{
const int N=1<<21,g=3;
int tr[N],k,a[N],b[N];ll pw[N];
void init(int n){
for(k=2;k<=n;k<<=1);
for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|(i&1?k/2:0);
pw[k/2]=1;pw[k/2+1]=mpow(g,(mod-1)/k);
for(int i=k/2+2;i<k;i++) pw[i]=pw[i-1]*pw[k/2+1]%mod;
for(int i=k/2-1;i;i--) pw[i]=pw[i<<1];
}
void ntt(int *A,int k,int flag){
static ull a[N];for(int i=0;i<k;i++) a[tr[i]]=A[i];
for(int i=2;i<=k;i<<=1){
ll *e=pw+i/2;
for(int j=0;j<k;j+=i){
for(int h=j;h<j+i/2;h++){
int x=a[h+i/2]*e[h-j]%mod;
a[h+i/2]=a[h]+mod-x;a[h]+=x;
}
}
if(i==(1<<18)){
for(int j=0;j<k;j++) a[j]%=mod;
}
}
for(int i=0;i<k;i++) A[i]=a[i]%mod;
if(flag) return;
reverse(A+1,A+k);
ll iv=mpow(k);for(int i=0;i<k;i++) A[i]=A[i]*iv%mod;
}
namespace Public{
poly operator *(const poly &A,const poly &B){
if(A.empty()||B.empty()) return poly({});
int n=A.size(),m=B.size(),lim=n+m-1;
init(lim);
copy(A.begin(),A.end(),a);fill(a+n,a+k,0);
copy(B.begin(),B.end(),b);fill(b+m,b+k,0);
ntt(a,k,1);ntt(b,k,1);
for(int i=0;i<k;i++) a[i]=1ll*a[i]*b[i]%mod;
ntt(a,k,0);
return poly(a,a+lim);
}
poly& operator *=(poly &A,const poly &B){
return A=A*B;
}
poly operator /(const poly &A,const poly &B){
poly C=A,D=B;
reverse(D.begin(),D.end());
C*=D;
return poly(C.begin()+int(D.size())-1,C.end());
}
poly& operator /=(poly &A,const poly &B){
return A=A/B;
}
poly operator *(const poly &A,const int B){
poly C=A;for(int i=0;i<C.size();i++) C[i]=1ll*C[i]*B%mod;
return C;
}
poly& operator *=(poly &A,const int &B){
return A=A*B;
}
poly operator +(const poly &A,const poly &B){
poly C(max(A.size(),B.size()));
for(int i=0;i<A.size();i++) C[i]=A[i];
for(int i=0;i<B.size();i++) C[i]=(B[i]+C[i])%mod;
return C;
}
poly& operator +=(poly &A,const poly &B){
return A=A+B;
}
poly operator -(const poly &A,const poly &B){
poly C(max(A.size(),B.size()));
for(int i=0;i<A.size();i++) C[i]=A[i];
for(int i=0;i<B.size();i++) C[i]=(C[i]+mod-B[i])%mod;
return C;
}
poly& operator -=(poly &A,const poly &B){
return A=A-B;
}
poly operator %(const poly &A,const int &B){
poly C=A;
if(C.size()>B) C.resize(B);
return C;
}
poly& operator %=(poly &A,const int B){
return A=A%B;
}
poly operator <<(const poly &A,const int &B){
poly C(A.size()+B);
copy(all(A),C.begin()+B);
return C;
}
poly& operator <<=(poly &A,const int &B){
return A=A<<B;
}
poly operator >>(const poly &A,const int &B){
if(B>=A.size()) return poly({});
return poly(A.begin()+B,A.end());
}
poly& operator >>=(poly &A,const int &B){
return A=A>>B;
}
poly inve(poly A,int n=-1){
if(n==-1) n=A.size();
if(n==1) return poly({mpow(A[0])});
poly A0=inve(A%(n+1>>1),n+1>>1);
return A0*(poly({2})-A*A0%n)%n;
}
poly sqrt(poly A,int n=-1){
if(n==-1) n=A.size();
if(n==1) return poly({1});
poly A0=sqrt(A%(n+1>>1),n+1>>1);
return (A0*A0%n+A)*inve(A0,n)%n*(mod+1>>1);
}
poly der(poly A){
poly B(A.size()-1);
for(int i=1;i<A.size();i++) B[i-1]=1ll*A[i]*i%mod;
return B;
}
poly integ(poly A){
poly B(A.size()+1);
static ll inv[N];inv[1]=1;for(int i=2;i<=A.size();i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
for(int i=0;i<A.size();i++) B[i+1]=inv[i+1]*A[i]%mod;
return B;
}
poly ln(poly A,int n=-1){
if(n==-1) n=A.size();
return integ(der(A)*inve(A,n)%n)%n;
}
poly exp(poly A,int n=-1){
if(n==-1) n=A.size();
if(n==1) return poly({1});
poly A0=exp(A%(n+1>>1),n+1>>1);
return A0*(poly({1})-ln(A0,n)+A)%n;
}
poly mPow(poly A,int n,ll k){gdb(n,k);
auto p=find_if(A.begin(),A.end(),[](ll x){return x;})-A.begin();
if(p==A.size()) return A;
poly B(A.size()-p);for(int i=p;i<A.size();i++) B[i-p]=A[i];
ll v=mpow(B[0],k%Mod),iv=mpow(B[0]);
for(ll &i:B) i=i*iv%mod;B=ln(B,n);
for(ll &i:B) i=k%mod*i%mod;B=exp(B,n);
for(ll &i:B) i=i*v%mod;
for(int i=n-1;~i;i--) B[i]=(i>=1ll*k*p?B[i-k*p]:0);
return B;
}
}
}using namespace Poly::Public;
int n,k;
ll m;
poly mul(poly A,poly B,int det=0){
A*=B;
poly C(n+1);
for(int i=0;i<=n;i++) C[i]=(A[i+det]>0);
return C;
}
poly mypow(poly A,int k){
if(k==1){
poly C(n+1);
for(int i=0;i+::k<=n;i++) C[i]=A[i+::k];
return C;
}
poly B=mypow(A,k>>1);
B=mul(B,B);
if(k&1) B=mul(B,A,::k);
return B;
}
void Solve(){
scanf("%d%lld",&n,&m);
poly A(n+1);
k=m/n;
for(int i=1;i<=n;i++){
int x;scanf("%d",&x);
A[x]=1;
}
A=mypow(A,n);
puts(A[m%n]?"YES":"NO");
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14156kb
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: 4ms
memory: 14132kb
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 NO YES YES YES NO 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 Y...
result:
wrong answer expected YES, found NO [25th token]