QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91620 | #5827. 异或图 | HL | 10 | 158ms | 628524kb | C++14 | 3.4kb | 2023-03-29 10:15:43 | 2023-03-29 10:15:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define lll __int128
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define pb emplace_back
const int N=16;
const int mod=998244353,iv2=mod+1>>1;
inline int add(int x,int y){return x+y+(x+y<0?mod:(x+y<mod?0:-mod));}
inline int mul(int x,int y){return (ll)x*y%mod;}
inline void ADD(int &x,int y){x=add(x,y);}
inline void MUL(int &x,int y){x=mul(x,y);}
inline int qpow(int x,int y){int res=1;while(y){if(y&1)MUL(res,x);MUL(x,x),y>>=1;}return res;}
int fac[N],ifac[N],F[N];
inline int bnm(int x,int y){return x>=y?mul(fac[x],mul(ifac[x-y],ifac[y])):0;}
inline void init(int n)
{
fac[0]=ifac[0]=1;
F[0]=1,F[1]=0;
for(int i=2;i<=n;i++)F[i]=mul(i-1,add(F[i-1],F[i-2]));
for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
ifac[n]=qpow(fac[n],mod-2);
for(int i=n-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
int a[N],e[N],tot,xs[N];
pii G[N*N];
const int CN=2e7+7;
string cd[CN];map<int,int>id;
const int MOD=10000002006032473,B=131;
inline int hsh(const string s)
{
int res=0;
for(auto x:s)res=(res*B+x-'a'+1)%MOD;
return res;
}
inline string re(const string s)
{
string t;
vector<int>mp(131,0);
int cnt=0;
for(auto x:s)
{
if(!mp[x])mp[x]=++cnt;
t+=mp[x]+'a'-1;
}
return t;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,c;
cin>>n>>m>>c;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)
{
int x,y;cin>>x>>y;
e[x]|=1<<y-1,e[y]|=1<<x-1;
G[i]=mk(x,y);
}
for(int i=1;i<=n;i++)cd[1]+=i+'a'-1;
id[hsh(cd[1])]=++tot;
queue<int>q;q.push(1);
while(!q.empty())
{
int ID=q.front();q.pop();
string s=cd[ID];//cout<<ID<<endl;
for(int i=1;i<=m;i++)
{
int x=G[i].fi,y=G[i].se;
if(s[x-1]==s[y-1])continue;
//cout<<x<<" "<<y<<endl;
string t=s;
for(auto &c:t)if(c==s[y-1])c=s[x-1];
t=re(t);int H=hsh(t);
if(!id[H])
{
id[H]=++tot;
cd[tot]=t;q.push(tot);
}
}
}
int ANS=0;//cout<<tot<<endl;
for(int cc=1;cc<=tot;cc++)
{
int ans=0;//cout<<cd[cc]<<" "<<xs[cc]<<endl;
vector<int>b(n+2,2e18),cnt(n+2,0);
for(int i=1;i<=n;i++)
{
int col=cd[cc][i-1]-'a'+1;
//cout<<col<<" \n"[i==n];
b[col]=min(b[col],a[i]);//////
cnt[col]++;
}
//for(int i=1;i<=n;i++)cout<<b[i]<<" \n"[i==n];
int X=0;
for(int B=59;B;B--)
{
int f0=1,f1=1,w=1,o=0,M=(1ll<<B)%mod;//cout<<M<<endl;
for(int i=1;i<=n;i++)
{
int v=b[i]&(1ll<<B)-1ll;v++,v%=mod;
if(b[i]&1ll<<B)
{
MUL(f0,add(v,M)),MUL(f1,add(-v,M)),MUL(w,v),o^=1;
}
else
{
MUL(f0,v),MUL(f1,v),MUL(w,v);
}
X^=b[i]&1ll<<B;
}
bool whi=c&1ll<<B;
if(whi)
{
int F=add(f0,-f1);
if(whi==o)ADD(F,-mul(w,2));//cout<<F<<" "<<w<<": \n";
ADD(ans,mul(F%mod,qpow(iv2,B+1)));
}
else
{
int F=add(f0,f1);
if(whi==o)ADD(F,-mul(w,2));//cout<<F<<" "<<w<<": \n";
ADD(ans,mul(F%mod,qpow(iv2,B+1)));
}
//cout<<ans<<endl;
//cout<<X<<" "<<c<<" "<<(c&(1ll<<B)-1ll)<<endl;
if(X!=(c^(c&(1ll<<B)-1ll)))break;//cout<<B<<endl;
}
//cout<<ans<<endl<<X<<endl;
if((X>>1)==(c>>1))
{
int CNT=0;
for(int i=1;i<=n;i++)
{
if(b[i]&1)CNT++;
}
if(CNT)
{
ADD(ans,qpow(2,CNT-1));
}
else if(X==c)ADD(ans,1);
}
//ADD(ANS,mul(xs[cc],ans));
cout<<ans<<endl;
}
//cout<<ANS;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 158ms
memory: 628448kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
92 120 96 96 120 180 96 10420531 269099583 10420531 10420531 15630796 10420531 15630796 308879087
result:
wrong answer 1st numbers differ - expected: '44', found: '92'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 10
Accepted
Test #47:
score: 10
Accepted
time: 135ms
memory: 628480kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
231790380
result:
ok 1 number(s): "231790380"
Test #48:
score: 0
Accepted
time: 132ms
memory: 628524kb
input:
11 0 101435837408688522 638776638580507479 933944392115323974 19098604312360490 142362319980029593 419910251764515410 275591812677260089 770239593400917018 928344484461634421 67340905784404712 378109786925249078 110881245457449811
output:
242383534
result:
ok 1 number(s): "242383534"
Test #49:
score: 0
Accepted
time: 144ms
memory: 628472kb
input:
9 0 100988561775675251 622570387572403506 684352103903274038 784649864569409753 270298495621205212 56183537059869110 346856482529145989 86639702870530669 607198038565138736 14747634008501988
output:
20893166
result:
ok 1 number(s): "20893166"
Test #50:
score: 0
Accepted
time: 129ms
memory: 628488kb
input:
10 0 839910859917247463 611237879350518457 292219463776059962 548211857317940894 822255554598388425 335628456629874391 774414280870858683 882480367082748768 654587410087321403 74330774886125511 22894883233341926
output:
61697734
result:
ok 1 number(s): "61697734"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%