QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#353467 | #4782. 完美的旅行 | ydzr00000 | 0 | 35ms | 14096kb | C++20 | 2.5kb | 2024-03-14 09:47:02 | 2024-03-14 09:47:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int a[65][65];
struct Matrix{
int mat[68][68];
int n,m;
Matrix(){
memset(mat,0,sizeof(mat));
}
friend inline Matrix operator*(Matrix a,Matrix b)
{
assert(a.m==b.n);
Matrix c;
c.n=a.n;c.m=b.m;
for(int i=0;i<a.n;i++)
for(int j=0;j<b.m;j++)
for(int k=0;k<a.m;k++)
c.mat[i][j]=(c.mat[i][j]+a.mat[i][k]*b.mat[k][j]%mod)%mod;
return c;
}
};
struct Vector{
int vec[68];
int n;
int &operator [](int x)
{
return vec[x];
}
Vector(){
memset(vec,0,sizeof(vec));
}
friend inline long long operator*(Vector a,Vector b)
{
assert(a.n==b.n);
long long ans=0;
for(int i=0;i<a.n;i++)
ans=(ans+a.vec[i]*b.vec[i]%mod)%mod;
return ans;
}
friend inline Vector operator*(Vector a,Matrix b)
{
assert(a.n==b.n);
Vector c;
c.n=b.m;
for(int i=0;i<b.m;i++)
for(int j=0;j<a.n;j++)
c.vec[i]=(c.vec[i]+a.vec[j]*b.mat[j][i]%mod)%mod;
return c;
}
friend inline Vector operator*(Matrix a,Vector b)
{
assert(a.m==b.n);
Vector c;
c.n=a.n;
for(int i=0;i<a.n;i++)
for(int j=0;j<b.n;j++)
c.vec[i]=(c.vec[i]+a.mat[i][j]*b.vec[j]%mod)%mod;
return c;
}
}U[151],V[151];
long long dp[20001][65];
inline Matrix qpow(Matrix a,long long b)
{
assert(a.n==a.m);
Matrix res;
res.n=res.m=a.n;
for(int i=0;i<res.n;i++)
res.mat[i][i]=1;
while(b)
{
if(b&1)
res=res*a;
a=a*a;
b>>=1;
}
return res;
}
void FWTand(long long *f,int n,int c)
{
for(int l=2,k=1;l<=n;l<<=1,k<<=1)
for(int i=0;i<n;i+=l)
for(int j=0;j<k;j++)
f[i+j]=(f[i+j]+f[i+j+k]*c+mod)%mod;
};
int main(){
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&a[i][j]);
int len=(int)sqrt(1.00*m)+1;
for(int sta=0;sta<n;sta++)
{
Matrix base;
base.n=base.m=n;
U[0].n=V[0].n=n;
for(int i=0;i<n;i++)
{
int sum=0;
for(int j=0;j<n;j++)
{
base.mat[j][i]=a[j][i];
if((j&sta)==sta)
sum=(sum+a[j][i])%mod;
}
U[0][i]=sum;
V[0][i]=((i&sta)==sta);
for(int j=0;j<n;j++)
if((j&sta)==sta)
base.mat[j][i]=(base.mat[j][i]+sum)%mod;
}
for(int i=1;i<=len;i++)
U[i]=U[i-1]*base;
base=qpow(base,len);
for(int i=1;i<=len;i++)
V[i]=base*V[i-1];
for(int i=1;i<=m;i++)
dp[i][sta]=U[(i-1)%len]*V[(i-1)/len];
}
int ans=0;
for(int i=1;i<=m;i++)
{
FWTand(dp[i],n,-1);
for(int j=0;j<n;j++)
ans^=dp[i][j];
}
printf("%d\n",ans);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3980kb
input:
4 20 53674686 128460215 363694167 120271218 578912024 941426068 993595265 587468617 731649477 694107878 355552389 226535630 99325151 243772822 66420647 578481511
output:
1025923981
result:
wrong answer 1st numbers differ - expected: '588479706', found: '1025923981'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 35ms
memory: 14096kb
input:
16 20000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14 2 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 4 5 6 7 0 1 2 3 12 13 14 15 8 9 10 11 5 4 7 6 1 0 3 2 13 12 15 14 9 8 11 10 6 7 4 5 2 3 0 1 14 15 12 13 10 11 8 9 7 6 5 4 3 2 1 0 15 14 13 ...
output:
408733978
result:
wrong answer 1st numbers differ - expected: '97601915', found: '408733978'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%