QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301794#5827. 异或图cryozwq20 35ms71708kbC++144.2kb2024-01-10 11:51:162024-01-10 11:51:16

Judging History

你现在查看的是最新测评结果

  • [2024-01-10 11:51:16]
  • 评测
  • 测评结果:20
  • 用时:35ms
  • 内存:71708kb
  • [2024-01-10 11:51:16]
  • 提交

answer

#include<bits/stdc++.h>
#define mp make_pair
#define fr first
#define sc second
using namespace std;
typedef long long ll;
const ll mod=998244353;
const ll inv2=(mod+1)/2ll;
const int maxn=4e6+5;
const int maxS=(1<<15)+5;
bool con[maxS];
bool g[20][20];
ll lm[20];
ll lim[20];
int n,m;
ll c;
ll f[20][2][2],a[20];
ll ipw[maxn];
ll calc(ll *l,int N,ll C){
    ll ans=0;
    for(ll i=59;i>=0;i--){
    	for(int j=1;j<=N;j++){
            for(int a=0;a<=1;a++){
                for(int b=0;b<=1;b++){
                    f[j][a][b]=0;
                }
            }
        }
        f[0][0][0]=1;
        for(int j=1;j<=N;j++){
            if((l[j]&(1ll<<i))){
                ll s1=(1ll<<i),s2=l[j]-s1;
                f[j][0][0]=f[j-1][0][1]*s2%mod;
                f[j][0][1]=f[j-1][0][0]*s2%mod;
                f[j][1][0]=(f[j-1][0][0]*s1%mod+f[j-1][1][1]*s2%mod+f[j-1][1][0]*s1%mod)%mod;
                f[j][1][1]=(f[j-1][0][1]*s1%mod+f[j-1][1][0]*s2%mod+f[j-1][1][1]*s1%mod)%mod;
            }
            else{
                for(int a=0;a<=1;a++){
                    for(int b=0;b<=1;b++){
                        f[j][a][b]=f[j-1][a][b]*l[j]%mod;
                    }
                }
            }
        }
    	if((C&(1ll<<i)))ans=(ans+f[N][1][1]*ipw[i]%mod)%mod;
        else ans=(ans+f[N][1][0]*ipw[i]%mod)%mod;
    	int cnt=0;
        for(int j=1;j<=N;j++){
            if((l[j]&(1ll<<i))){
                cnt++;
                l[j]^=(1ll<<i);
            }
        }
        if(((cnt&1)^((C>>i&1))))return ans;
    }
    return ans;
}
#define lowbit(i) ((i)&(-(i)))
ll dp[maxS],pw[maxn],xs[maxn];
int ch[maxS],lg[maxS];
int popcnt[maxn];
int id[maxn];
pair<ll,int>tmp[maxn];
int main(){
    ipw[0]=1;
    for(int i=1;i<maxn;i++)ipw[i]=ipw[i-1]*inv2%mod;
    pw[0]=1;
    for(int i=1;i<maxn;i++)pw[i]=pw[i-1]*3ll%mod;
    for(int i=1;i<maxS;i++)ch[i]=ch[i>>1]*3ll+(i&1),popcnt[i]=popcnt[i>>1]+(i&1);
    for(int i=1;(1<<(i-1))<maxS;i++)lg[(1<<i-1)]=i;
    scanf("%d%d%lld",&n,&m,&c);
    for(int i=1;i<=n;i++)scanf("%lld",&lim[i]),lim[i]++,tmp[i]=mp(lim[i],i);
    sort(tmp+1,tmp+n+1);
    sort(lim+1,lim+n+1);
    for(int i=1;i<=n;i++)id[tmp[i].sc]=i;
    for(int i=1,u,v;i<=m;i++){
        scanf("%d%d",&u,&v);
        g[id[u]][id[v]]=g[id[v]][id[u]]=1;
    }
    for(int S=0;S<(1<<n);S++){
        for(int i=1;i<=n;i++){
            if(!(S&(1<<i-1)))continue;
            for(int j=1;j<=n;j++){
                if(!(S&(1<<j-1)))continue;
                if(i==j)continue;
                if(g[i][j])con[S]=1;
            }
        }
    }
    for(int S=1;S<(1<<n);S++){
    	xs[S]=0;        
        if(!con[S])xs[S]=1;
        int ts=(S^(lowbit(S)));
    	for(int T=ts;T;T=((T-1)&ts)){ 
    		if(!con[T])xs[S]=(xs[S]-xs[S^T]+mod)%mod;
    	}
        // cout<<S<<" "<<xs[S]<<endl;
    }
    dp[0]=1;
    int cnt=0;
    int all=(1<<n)-1;
    for(int S=0;S<pw[n];S++){
        if(!dp[S])continue;
        // cout<<S<<" "<<dp[S]<<endl;
        int ts=0,T=S;
        for(int i=n-1;i>=0;i--){
            if(T>=pw[i]){
                ts+=(1<<i); 
                T%=pw[i];
            } 
        }
        ts=(all^ts);
        // if(!ts)continue;
        int tts=(ts^(lowbit(ts)));
        // cout<<S<<" "<<tts<<endl;
        for(int tt=tts;;tt=((tt-1)&tts)){ 
            int T=(tt|(lowbit(ts)));
    		int news=S+ch[T];
            if(popcnt[T]&1){
                news+=ch[lowbit(ts)];
                // cout<<news<<":"<<S<<endl;
                dp[news]=(dp[news]+dp[S]*xs[T]%mod)%mod;
            }
            else{
                // cout<<news<<":"<<S<<endl;
                dp[news]=(dp[news]+dp[S]*xs[T]%mod*lim[lg[lowbit(ts)]]%mod)%mod;
            } 
            if(!tt)break;
        }
    }
    ll ans=0;
    for(int S=0;S<(1<<n);S++){
        int ts=ch[S]+ch[all];
        if(!dp[ts])continue;
        int tt=0;
        for(int i=1;i<=n;i++){
            if((S&(1<<i-1)))lm[++tt]=lim[i];
        }
        // for(int i=1;i<=tt;i++){
        //     cout<<lm[i]<<" ";
        // }
        // cout<<calc(lm,tt,c)<<" "<<dp[ts]<<endl;
        ans=(ans+dp[ts]*calc(lm,tt,c)%mod)%mod;
    }
    cout<<ans;
    return 0;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 20ms
memory: 69412kb

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: 0
Accepted
time: 35ms
memory: 70196kb

input:

4 4 6
12 14 14 5
4 2
1 4
3 2
1 2

output:

798

result:

ok 1 number(s): "798"

Test #3:

score: 0
Accepted
time: 23ms
memory: 70136kb

input:

3 3 2
10 4 11
2 1
3 2
1 3

output:

33

result:

ok 1 number(s): "33"

Test #4:

score: 0
Accepted
time: 31ms
memory: 70696kb

input:

4 0 4
9 8 5 2

output:

148

result:

ok 1 number(s): "148"

Test #5:

score: 0
Accepted
time: 35ms
memory: 71392kb

input:

5 6 14
12 15 13 13 12
3 1
2 4
2 5
2 1
5 3
4 5

output:

21337

result:

ok 1 number(s): "21337"

Test #6:

score: 0
Accepted
time: 29ms
memory: 71652kb

input:

4 5 5
5 2 4 13
2 1
3 4
1 4
4 2
3 2

output:

42

result:

ok 1 number(s): "42"

Test #7:

score: 0
Accepted
time: 31ms
memory: 68976kb

input:

4 4 3
13 7 8 12
4 1
3 1
2 4
4 3

output:

552

result:

ok 1 number(s): "552"

Test #8:

score: 0
Accepted
time: 27ms
memory: 69780kb

input:

4 2 12
1 12 4 11
2 1
3 1

output:

70

result:

ok 1 number(s): "70"

Test #9:

score: 0
Accepted
time: 20ms
memory: 69216kb

input:

5 5 6
10 7 8 2 13
1 5
1 3
2 1
4 3
5 3

output:

1231

result:

ok 1 number(s): "1231"

Test #10:

score: 0
Accepted
time: 27ms
memory: 69476kb

input:

5 7 9
6 7 13 15 12
1 3
5 3
5 2
4 5
4 3
4 1
3 2

output:

6223

result:

ok 1 number(s): "6223"

Test #11:

score: 0
Accepted
time: 31ms
memory: 71708kb

input:

3 0 3
15 7 12

output:

104

result:

ok 1 number(s): "104"

Test #12:

score: 0
Accepted
time: 27ms
memory: 70720kb

input:

3 2 9
10 6 5
1 2
1 3

output:

17

result:

ok 1 number(s): "17"

Test #13:

score: 0
Accepted
time: 31ms
memory: 70600kb

input:

5 5 11
7 9 15 9 9
5 4
5 1
5 2
1 3
3 4

output:

5224

result:

ok 1 number(s): "5224"

Test #14:

score: 0
Accepted
time: 27ms
memory: 70712kb

input:

5 0 12
9 8 14 11 2

output:

3006

result:

ok 1 number(s): "3006"

Test #15:

score: 0
Accepted
time: 23ms
memory: 69108kb

input:

3 1 1
6 10 4
3 1

output:

30

result:

ok 1 number(s): "30"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #16:

score: 0
Wrong Answer
time: 29ms
memory: 69844kb

input:

9 27 705410105529944560
929827299070190972 733413770730537329 473007347105710981 190062421504120247 918561152768663129 196040702922254016 981530663192980241 203295856357272834 337150461958783092
2 8
7 9
8 9
2 3
9 2
2 7
9 5
9 4
4 8
1 7
6 3
6 1
4 1
6 5
2 4
2 1
9 3
9 6
7 3
7 5
5 2
4 5
2 6
3 1
3 8
4 3
8 6

output:

-562906243

result:

wrong answer 1st numbers differ - expected: '5392583', found: '-562906243'

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:

100%
Accepted

Dependency #2:

0%