QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218914 | #6555. Sets May Be Good | YunQian | WA | 1ms | 3684kb | C++14 | 2.3kb | 2023-10-18 20:30:56 | 2023-10-18 20:30:57 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
const int mod=998244353;
int ksm(int x,int y,int p=mod){
int ans=1;
for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
void Assert(bool c,int L=0){if(!c){cout<<"Assertion Failed at "<<L<<endl;exit(0);}}
void cmax(int &x,int v){x=max(x,v);}
void cmin(int &x,int v){x=min(x,v);}
const int N=1005;
bitset<N>G[N];
int n,m,f[2][2],g[2][2];
signed main(void){
#ifdef YUNQIAN
freopen("in.in","r",stdin);
#endif
n=read(),m=read();
for(int i=1;i<=m;i++){
int u=read(),v=read();
G[u].flip(v);
}
for(int i=1;i<=n;i++){
// cout<<"i = "<<i<<endl;
// step 1
for(int j=i+1;j<=n;j++)if(G[i][j])G[j].flip(i),G[i][j]=0;
auto print=[&](){for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cout<<G[i][j]<<" \n"[j==n];};
// cout<<"step1 -> G = \n";print();
// step 2
int p=-1;
for(int j=i+1;j<=n;j++)if(G[j][i]!=0)p=j;
if(p==-1)continue;
// cout<<"p = "<<p<<endl;
swap(G[p],G[i+1]);
for(int j=i+1;j<=n;j++){
// cout<<"j = "<<j<<" G["<<j<<"]["<<p<<"] = "<<G[j][p]<<" G["<<j<<"]["<<i+1<<"] = "<<G[j][i+1]<<endl;
bool t=G[j][p];
G[j][p]=G[j][i+1],G[j][i+1]=t;
// cout<<"j = "<<j<<" G["<<j<<"]["<<p<<"] = "<<G[j][p]<<" G["<<j<<"]["<<i+1<<"] = "<<G[j][i+1]<<endl;
}
// cout<<"step2 -> G = \n";print();
// step 3
bitset<N>f;
for(int j=i+2;j<=n;j++)if(G[j][i])G[j]^=G[i+1],f[j]=1;
for(int j=i+2;j<=n;j++)if(G[j][i+1])G[j]^=f;
// cout<<"step3 -> G = \n";print();
}
f[0][0]=1;
for(int i=1;i<=n;i++){
memset(g,0,sizeof(g));
for(int x=0;x<=1;x++)for(int y=0;y<=1;y++){
add(g[0][y],f[x][y]);
if(x==0)add(g[1][y],f[x][y^G[i][i]]);
else add(g[1][y],f[x][y^G[i][i]^G[i][i-1]]);
}
for(int x=0;x<=1;x++)for(int y=0;y<=1;y++)f[x][y]=g[x][y];
}
int ans=f[0][0];add(ans,f[1][0]);
cout<<ans<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
input:
5 5 1 2 2 3 3 4 4 5 1 5
output:
16
result:
ok 1 number(s): "16"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
3 0
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
2 1 1 2
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
8
result:
wrong answer 1st numbers differ - expected: '6', found: '8'