QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99838 | #5827. 异或图 | zaneyu | 0 | 2ms | 4264kb | C++20 | 4.7kb | 2023-04-23 20:36:19 | 2023-04-23 20:36:23 |
Judging History
answer
/*input
3 1 2
1 2 3
1 2
1 1 1
2 2 1
3 0 2
1 1 1
4 4 1
1 1 1
2 2 1
3 0 2
1 1 1
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=15+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-4;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<P.f<<' '<<P.s;
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":"");
return out;
}
ll mult(ll a,ll b){
return a*b%MOD;
}
ll mypow(ll a,ll b){
a%=MOD;
if(a==0) return 0;
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=(res*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return res;
}
ll arr[maxn];
int ipw[60];
ll c;
int get(vector<ll> v){
ll ans=0;
for(int j=59;j>=0;j--){
ll c0=1,c1=0;
ll al=1;
int cnt=0;
for(auto x:v){
ll z=(x&((1LL<<j)-1))+1;
z%=MOD;
if(x&(1LL<<j)){
++cnt;
ll p0=c0,p1=c1;
ll o=(1LL<<j);
o%=MOD;
c0=(p1*o%MOD+p0*z%MOD)%MOD;
c1=(p1*z%MOD+p0*o%MOD)%MOD;
}
else{
c0*=z,c1*=z;
c0%=MOD,c1%=MOD;
}
al=(al*z)%MOD;
}
c0+=MOD-al;
c0%=MOD;
c1*=ipw[j],c0*=ipw[j];
c1%=MOD,c0%=MOD;
if(cnt){
if((cnt%2)!=((c>>j)&1)){
ans+=c1;
}
else{
ans+=c0;
}
}
ans%=MOD;
if((cnt%2)!=((c>>j)&1)){
break;
}
if(j==0) ++ans;
ans%=MOD;
}
return ans;
}
int ed[maxn];
int tot[(1<<15)],mn[(1<<15)];
int cof[(1<<15)];
ll tmp[(1<<15)];
vector<pii> dp[(1<<15)];
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,m;
cin>>n>>m>>c;
ipw[0]=1;
REP1(i,59){
ipw[i]=1LL*ipw[i-1]*((MOD+1)/2)%MOD;
}
REP(i,n) cin>>arr[i];
REP(i,m){
int a,b;
cin>>a>>b;
--a,--b;
ed[a]|=(1<<b),ed[b]|=(1<<a);
}
REP(i,(1<<n)){
int p=-1;
REP(j,n){
if(i&(1<<j)){
if(p==-1 or arr[j]<arr[p]) p=j;
tot[i]+=__builtin_popcount(ed[j]&i);
}
}
mn[i]=p;
}
REP1(i,(1<<n)-1){
int l=lowb(i);
int m=(i^l);
cof[i]=1;
if(tot[i]) cof[i]=0;
if(!m) continue;
for(int j=(m&(m-1));;j=(j-1)&m){
if(!ed[m^j]){
cof[i]+=MOD-cof[l^j];
cof[i]%=MOD;
}
if(!j) break;
}
//cout<<i<<' '<<cof[i]<<'\n';
}
dp[0].pb({1,0});
REP1(i,(1<<n)-1){
int l=lowb(i);
int m=(i^l);
for(int j=m;;j=((j-1)&m)){
int k=(l^j);
if(!cof[k]) continue;
int y=0;
ll mul=1;
if(__builtin_popcount(k)%2){
y=(1<<mn[k]);
}
else{
mul=(arr[mn[k]]+1)%MOD;
}
for(auto x:dp[i^k]){
tmp[x.s^y]+=1LL*mul*x.f%MOD*cof[k]%MOD;
tmp[x.s^y]%=MOD;
}
if(!j) break;
}
for(int j=i;;j=((j-1)&i)){
if(tmp[j]){
dp[i].pb({tmp[j],j});
tmp[j]=0;
}
if(!j) break;
}
}
ll ans=0;
for(auto x:dp[(1<<n)-1]){
vector<ll> vv;
REP(j,n){
if(x.s&(1<<j)) vv.pb(arr[j]);
}
ans+=1LL*x.f*get(vv)%MOD;
ans%=MOD;
}
cout<<ans<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 0ms
memory: 4264kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
44
result:
ok 1 number(s): "44"
Test #2:
score: -20
Wrong Answer
time: 2ms
memory: 4172kb
input:
4 4 6 12 14 14 5 4 2 1 4 3 2 1 2
output:
846
result:
wrong answer 1st numbers differ - expected: '798', found: '846'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #47:
score: 0
Runtime Error
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%