QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100001 | #6344. The Best Problem of 2021 | aurelion_sol | WA | 4ms | 6940kb | C++14 | 3.2kb | 2023-04-24 12:33:58 | 2023-04-24 12:34:01 |
Judging History
answer
#include<bits/stdc++.h>
#define rp(i,a,b) for(int i=a;i<=b;++i)
#define pr(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
//xiaoyaowudi
constexpr int N(2010),p(998244353);
int n,x[N];
void init(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int m,cnt(0);
std::cin>>n>>m;
static bool hv[N];
static std::bitset<N> b[N];
static std::bitset<N> a[N],xb;
for(int i(1);i<=n;++i)
{
static char s[N];std::cin>>s;
for(int j(0);j<m;++j)
{
a[i][m-j-1]=(s[j]=='1');
}
bool st(false);
for(int j(m-1);j>=0;--j) if(a[i][j])
{
if(hv[j])
{
a[i]^=b[j];
}
else
{
hv[j]=st=true;
b[j]=a[i];
break;
}
}
if(!st){std::cout<<0<<std::endl;exit(0);}
}
{
static char s[N];std::cin>>s;
for(int j(0);j<m;++j) xb[m-j-1]=(s[j]=='1');
}
for(int i(m-1);i>=0;--i) if(hv[i]) for(int j(i+1);j<m;++j) if(hv[j] && b[j][i]) b[j]^=b[i];
static std::bitset<N> cur;
for(int j(m-1);j>=0;--j) if(hv[j])
{
std::bitset<N> nw(cur^b[j]);
bool cap(true);
for(int t(m-1);t>=0;--t) if(xb[t]!=nw[t])
{
if(xb[t]<nw[t]) cap=false;
break;
}
if(cap) cur=nw,x[++cnt]=1;
else x[++cnt]=0;
}
if(!x[1]){std::cout<<0<<std::endl;exit(0);}
}
//~xiaoyaowudi
typedef long long ll;
constexpr int q(p-1);
inline int inc(int x,int y){
return x+=y-p,x+=x>>31&p;
}
inline int dec(int x,int y){
return x-=y,x+=x>>31&p;
}
inline int mul(int x,int y){
return ll(x)*y%p;
}
inline void upd(int&x,int y){
x=inc(x,y);
}
int ksm(int x,int y){
int z=1;
for(;y;y>>=1,x=mul(x,x))if(y&1)z=mul(x,z);
return z;
}
int ksm_e(int x,int y){
int z=1;
for(;y;y>>=1,x=ll(x)*x%q)if(y&1)z=ll(x)*z%q;
return z;
}
int v[N],w[N],wx[N][2],a2[N],i2[N],h[N][N],g[N][N][2],f[N][N][3],a[N],b[N];
void init_val(){
rp(i,0,n){
v[i]=ksm(2,ksm_e(2,i));
w[i]=ksm(2,i);
wx[i][0]=w[i];
wx[i][1]=0;
}
a2[0]=1;
rp(i,1,n){
a2[i]=mul(a2[i-1],w[i]-1);
}
i2[n]=ksm(a2[n],p-2);
pr(i,n,1){
i2[i-1]=mul(i2[i],w[i]-1);
}
}
int main(){
// freopen("1.in","r",stdin);
init();
init_val();
h[n+1][0]=1;
pr(i,n,2){
rp(j,0,n-i){
int u=mul(v[j],w[n-i-j]);
h[i][j]=inc(h[i][j],h[i+1][j]);
h[i][j+1]=inc(h[i][j+1],mul(u,h[i+1][j]));
}
}
g[n+1][0][0]=1;
pr(i,n,2){
rp(j,0,n-i){
int u=wx[n-i-j][x[i]];
int t=mul(v[j],w[n-i-j]);
// printf("(i j u t)=(%d %d %d %d)\n",i,j,u,t);
upd(g[i][j][1],mul(u,g[i+1][j][0]));
rp(k,0,1){
upd(g[i][j][k],g[i+1][j][k]);
upd(g[i][j+1][k],mul(t,g[i+1][j][k]));
}
}
}
f[n+1][0][0]=1;
f[n+1][0][2]=1;
pr(i,n,2){
rp(j,0,n-i){
int u=wx[n-i-j][x[i]];
upd(f[i][j][1],mul(u,f[i+1][j][0]));
rp(k,0,2){
int t=mul(w[n-i-j],k==2&&!x[i]?1:v[j]);
upd(f[i][j][k],f[i+1][j][k]);
upd(f[i][j+1][k],mul(t,f[i+1][j][k]));
}
}
if(x[i]){
rp(j,0,n-i){
upd(f[i][j][2],mul(w[n-i-j],f[i+1][j][0]));
upd(f[i][j+1][2],f[i+1][j][1]);
}
}
}
a[0]=a2[n];
rp(j,1,n){
int x=inc(h[2][j],inc(g[2][j-1][1],mul(v[j-1],f[2][j-1][2])));
a[j]=mul(x,a2[n-j]);
}
int s=0;
rp(i,0,n){
int u=mul(i2[i],ksm(2,i*(i-1)/2));
upd(s,mul(i&1?p-u:u,a[n-i]));
}
printf("%d\n",s);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5596kb
input:
4 4 0001 0010 0100 1000 1101
output:
7364
result:
ok 1 number(s): "7364"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5436kb
input:
3 2 00 00 00 11
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 4ms
memory: 5800kb
input:
2 3 110 101 101
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
3 10 1111100110 0011110100 0101100001 1110000001
output:
38
result:
ok 1 number(s): "38"
Test #5:
score: 0
Accepted
time: 2ms
memory: 5684kb
input:
7 13 1000101001000 1000000010000 1010101011111 1001100100111 1111111101100 0101010101110 1101100010100 1000010011001
output:
744450298
result:
ok 1 number(s): "744450298"
Test #6:
score: -100
Wrong Answer
time: 4ms
memory: 6940kb
input:
100 100 1111010111010001011111110010101001001101000000000000011000001100101000100011100011000000110000001010 1001001110111010100100010111100010111110101100101000010111001011111010111100111000000011101010100111 000011010111000100110100010010011101001111100110111000100101010001101100101011000111101101...
output:
184318487
result:
wrong answer 1st numbers differ - expected: '19562313', found: '184318487'