QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#816865 | #9870. Items | Coffins | WA | 160ms | 13912kb | C++14 | 1.8kb | 2024-12-16 18:46:39 | 2024-12-16 18:46:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1<<19;
const int p=998244353;
const int ig=(p+1)/3;
int n,k,l,a[N],q,r,d;ll m;
ll f[N],g[N],A[N],B[N];int rv[N];
ll ksm(ll a,ll b)
{
ll ans=1;while(b)
{
if(b&1)ans=ans*a%p;
a=a*a%p,b>>=1;
}return ans;
}
void init(int n)
{
for(int i=0;i<=n;i++)
{
rv[i]=rv[i>>1]>>1;
if(i&1)rv[i]|=(l>>1);
}
}void NTT(ll *a,int n,int o)
{
for(int i=0;i<n;i++)
if(rv[i]<i)swap(a[i],a[rv[i]]);
for(int d=1;d<n;d<<=1)
{
ll bs=ksm(ig,(p-1)/d/2);
if(~o)bs=ksm(bs,p-2);
for(int i=0;i<n;i+=(d<<1))
{
ll vl=1;
for(int j=i;j<i+d;j++)
{
ll x=a[j],y=a[j+d]*vl%p;
if((a[j]=x+y)>=p)a[j]-=p;
if((a[j+d]=x+p-y)>=p)a[j+d]-=p;
vl=vl*bs%p;
}
}
}if(o==-1)
{
const ll vl=ksm(n,p-2);
for(int i=0;i<n;i++)
a[i]=a[i]*vl%p;
}
}void mul(ll *f,ll *g)
{
for(int i=0;i<l;i++)A[i]=f[i];
for(int i=0;i<l;i++)B[i]=g[i];
NTT(A,l,1),NTT(B,l,1);
for(int i=0;i<l;i++)
A[i]=A[i]*B[i]%p;
NTT(A,l,-1);
for(int i=0;i<l;i++)
if(i+d<l)f[i]=A[i+d];
else f[i]=0;
}
void solve()
{
cin>>n>>m;k=n,q=m/n,r=m%n,d=n-r;
l=1;while(l<=(n<<2))l<<=1;init(l);
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=0;i<l;i++)f[i]=0;
for(int i=0;i<l;i++)g[i]=0;g[d]=1;
for(int i=1;i<=n;i++)
{
const int c=a[i]-q+d;
if(0<=c&&c<l)f[c]=1;
}
while(k)
{
if(k&1)mul(g,f);
mul(f,f),k>>=1;
}if(g[r+d])cout<<"Yes\n";
else cout<<"No\n";
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;cin>>t;while(t--)solve();return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13888kb
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: 0
Accepted
time: 16ms
memory: 13912kb
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:
ok 1314 token(s): yes count is 732, no count is 582
Test #3:
score: -100
Wrong Answer
time: 160ms
memory: 13832kb
input:
10000 4 1 0 0 0 0 4 1 0 0 0 1 4 1 0 0 0 2 4 1 0 0 0 3 4 1 0 0 0 4 4 1 0 0 1 0 4 1 0 0 1 1 4 1 0 0 1 2 4 1 0 0 1 3 4 1 0 0 1 4 4 1 0 0 2 0 4 1 0 0 2 1 4 1 0 0 2 2 4 1 0 0 2 3 4 1 0 0 2 4 4 1 0 0 3 0 4 1 0 0 3 1 4 1 0 0 3 2 4 1 0 0 3 3 4 1 0 0 3 4 4 1 0 0 4 0 4 1 0 0 4 1 4 1 0 0 4 2 4 1 0 0 4 3 4 1 0 ...
output:
No Yes No No No Yes Yes Yes Yes Yes No Yes No No No No Yes No No No No Yes No 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 Yes No No No Yes Yes Yes Yes Yes No Yes No No No No Yes No No No No Yes No No No No Yes No No No Yes Yes Yes Yes ...
result:
wrong answer expected YES, found NO [6270th token]