QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398350 | #4893. Imbalance | Iratis | 20 | 736ms | 36624kb | C++20 | 4.3kb | 2024-04-25 11:02:40 | 2024-04-25 11:02:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
bool ST;
const int N=120,M=(1<<21)+5,mod=998244353;
int n,ned,m;char str[N];
namespace Math
{
int fac[N],inv[N],upd,iv[N];
inline void add(int &x,const int &y){x+=y;if(x>=mod)x-=mod;}
inline void dec(int &x,const int &y){x-=y;if(x<0)x+=mod;}
inline int qp(int a,int n){int b=1;while(n){if(n&1)b=b*a%mod;a=a*a%mod,n>>=1;}return b;}
inline void PreC()
{
upd=N-1,fac[0]=1;for(int i=1;i<=upd;i++)fac[i]=fac[i-1]*i%mod;
inv[upd]=qp(fac[upd],mod-2);for(int i=upd-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
for(int i=1;i<=upd;i++)iv[i]=inv[i]*fac[i-1]%mod;
}
inline int C(int n,int m){if(n<m||m<0)return 0;return fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int P(int a,int b,int c,int d){c-=a,d-=b;return C(c,d);}
};
using namespace Math;
namespace Force
{
int f[M],g[M];
inline void main()
{
int S=(1<<ned-1);f[0]=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<S;j++)g[j]=f[j],f[j]=0;
for(int j=0;j<S;j++)if(g[j])
{
int to=(j<<1)&(S-1);
for(int v=0;v<2;v++)
{
if(i+1<=m&&v!=str[i+1]-'0')continue;
int A=__builtin_popcount(j),B=ned-1-A;if(v)A++;else B++;
if(i+1>=ned&&A==B)continue;add(f[to|v],g[j]);
}
}
}
int ans=0;for(int i=0;i<S;i++)add(ans,f[i]);cout<<ans<<'\n';
}
};
namespace Right
{
int upd=60,f[61][N][N],tot,id[N],s[N],val[N],dis;bool del[N][N];
struct Point{int x,y;}st[N],ed[N];int cnt,Ans,a[N][N];
inline void Start(int s)
{
if(del[0][s])return ;f[s][0][s]=1;
for(int i=0;i<=ned;i++)for(int j=0;j<=n;j++)if(!del[i][j])
{
if(i)add(f[s][i][j],f[s][i-1][j]);
if(i&&j)add(f[s][i][j],f[s][i-1][j-1]);
}
}
//start:(m,s[m]) ; end:(n%k,s[n]-(k/2)*(n/k))
inline int Det()
{
int f=0;
for(int i=1;i<=cnt;i++)
{
for(int j=i+1;j<=cnt;j++)if(a[j][i]){for(int k=1;k<=n;k++)swap(a[i][k],a[j][k]);f^=1;break;}
if(!a[i][i])return 0;int iv=qp(a[i][i],mod-2);
for(int j=i+1;j<=cnt;j++)
{
int d=a[j][i]*iv%mod;
for(int k=i;k<=cnt;k++)dec(a[j][k],a[i][k]*d%mod);
}
}
int ans=(f?mod-1:1);for(int i=1;i<=cnt;i++)ans=ans*a[i][i]%mod;return ans;
}
inline void Calc()
{
// cout<<"calc:";for(int i=1;i<=tot;i++)cout<<s[id[i]]<<" ";cout<<'\n';
cnt=0;cnt++,st[cnt]={m,s[m]},ed[cnt]={ned,s[ned]};
for(int i=1;i<tot;i++)cnt++,st[cnt]={0,s[id[i]]-dis*i},ed[cnt]={id[i+1]-id[i],s[id[i+1]]-dis*i};
// for(int i=1;i<=cnt;i++)cout<<st[i].x<<" "<<st[i].y<<" "<<ed[i].x<<" "<<ed[i].y<<'\n';
for(int i=1;i<=cnt;i++)for(int j=1;j<=cnt;j++)a[i][j]=0;
for(int i=2;i<=cnt;i++)for(int j=1;j<=cnt;j++)
{
int res=f[st[i].y][ed[j].x][ed[j].y];
for(int k=0;k<ed[cnt].x;k++)
{
dec(res,f[st[i].y][k][ed[cnt].y]*P(k+1,ed[cnt].y+1,ed[j].x,ed[j].y)%mod);
// cout<<"dec:"<<i<<" "<<j<<":"<<f[st[i].y][k][ed[cnt].y]*P(k+1,ed[cnt].y+1,ed[j].x,ed[j].y)%mod<<'\n';
}
a[i][j]=res;
}
for(int j=1;j<=cnt;j++)
{
int res=P(st[1].x,st[1].y,ed[j].x,ed[j].y);
for(int k=0;k<ed[cnt].x;k++)
{
dec(res,P(st[1].x,st[1].y,k,ed[cnt].y)*P(k+1,ed[cnt].y+1,ed[j].x,ed[j].y)%mod);
}a[1][j]=res;
}
// for(int i=1;i<=cnt;i++,cout<<'\n')for(int j=1;j<=cnt;j++)cout<<a[i][j]<<' ';
int w=Det();
// cout<<"profit="<<w<<'\n';
add(Ans,w);
}
void Count(int t)
{
if(t==tot+1){Calc();return ;}
int L=val[t-1],R=val[t-1]+id[t]-id[t-1];if(t<tot||n%ned==0)L+=dis+1;
for(int v=L;v<=R;v++)val[t]=v,s[id[t]]=v,Count(t+1);
}
inline int Get()
{
memset(f,0,sizeof(f)),tot=0,memset(del,0,sizeof(del));dis=ned/2;Ans=0;
for(int i=1,j=0;i<=m;i++)j+=(str[i]-'0'),del[i][j]=1,s[i]=j;for(int y=0;y<=upd;y++)Start(y);
for(int t=1;t<=n/ned;t++)id[++tot]=t*ned;if(n%ned!=0)id[++tot]=n;
for(int i=1;i<=tot;i++)cout<<id[i]<<" ";cout<<'\n';
Count(1);return Ans;
}
inline void main()
{
int p=Get();
for(int i=1;i<=n;i++){if(str[i]=='1')str[i]='0';else str[i]='1';}
int q=Get();add(p,q);
cout<<p<<'\n';
}
};
bool ED;
signed main()
{
// int time_st=clock();
cerr<<(&ST-&ED)/1024.0/1024<<endl;ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
PreC();cin>>n>>ned>>m;for(int i=1;i<=m;i++)cin>>str[i];
if(ned<=22){Force::main();}else {Right::main();}
// cerr<<(clock()-time_st)/1e6<<endl;return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3772kb
input:
2 2 0
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3924kb
input:
2 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3996kb
input:
3 2 0
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 10
Accepted
time: 1ms
memory: 3844kb
input:
3 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3884kb
input:
4 2 0
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 10
Accepted
time: 0ms
memory: 3840kb
input:
4 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 10
Accepted
time: 0ms
memory: 3932kb
input:
4 4 0
output:
10
result:
ok 1 number(s): "10"
Test #8:
score: 10
Accepted
time: 1ms
memory: 3968kb
input:
4 4 1 1
output:
5
result:
ok 1 number(s): "5"
Test #9:
score: 10
Accepted
time: 1ms
memory: 3964kb
input:
4 4 2 00
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 10
Accepted
time: 0ms
memory: 3884kb
input:
4 4 3 101
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 10
Accepted
time: 0ms
memory: 3864kb
input:
5 2 0
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 10
Accepted
time: 0ms
memory: 3996kb
input:
5 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 10
Accepted
time: 1ms
memory: 3848kb
input:
5 4 0
output:
14
result:
ok 1 number(s): "14"
Test #14:
score: 10
Accepted
time: 0ms
memory: 3992kb
input:
5 4 1 0
output:
7
result:
ok 1 number(s): "7"
Test #15:
score: 10
Accepted
time: 1ms
memory: 4060kb
input:
5 4 2 01
output:
3
result:
ok 1 number(s): "3"
Test #16:
score: 10
Accepted
time: 0ms
memory: 4068kb
input:
5 4 3 110
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 10
Accepted
time: 0ms
memory: 3828kb
input:
17 2 0
output:
2
result:
ok 1 number(s): "2"
Test #18:
score: 10
Accepted
time: 0ms
memory: 3892kb
input:
17 2 0
output:
2
result:
ok 1 number(s): "2"
Test #19:
score: 10
Accepted
time: 1ms
memory: 3848kb
input:
17 10 6 110111
output:
621
result:
ok 1 number(s): "621"
Test #20:
score: 10
Accepted
time: 0ms
memory: 4068kb
input:
17 10 2 11
output:
8413
result:
ok 1 number(s): "8413"
Test #21:
score: 10
Accepted
time: 0ms
memory: 3776kb
input:
18 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 10
Accepted
time: 0ms
memory: 3772kb
input:
18 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 10
Accepted
time: 0ms
memory: 3772kb
input:
18 8 5 00010
output:
918
result:
ok 1 number(s): "918"
Test #24:
score: 10
Accepted
time: 0ms
memory: 4060kb
input:
18 8 3 001
output:
3404
result:
ok 1 number(s): "3404"
Test #25:
score: 10
Accepted
time: 2ms
memory: 4508kb
input:
18 16 6 100011
output:
2458
result:
ok 1 number(s): "2458"
Test #26:
score: 10
Accepted
time: 1ms
memory: 4340kb
input:
18 16 8 00101101
output:
548
result:
ok 1 number(s): "548"
Test #27:
score: 10
Accepted
time: 0ms
memory: 3772kb
input:
19 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #28:
score: 10
Accepted
time: 0ms
memory: 4056kb
input:
19 2 0
output:
2
result:
ok 1 number(s): "2"
Test #29:
score: 10
Accepted
time: 1ms
memory: 3964kb
input:
19 6 2 00
output:
3413
result:
ok 1 number(s): "3413"
Test #30:
score: 10
Accepted
time: 0ms
memory: 3964kb
input:
19 6 1 1
output:
7012
result:
ok 1 number(s): "7012"
Test #31:
score: 10
Accepted
time: 1ms
memory: 3804kb
input:
19 12 10 1010110000
output:
266
result:
ok 1 number(s): "266"
Test #32:
score: 10
Accepted
time: 1ms
memory: 3868kb
input:
19 12 3 111
output:
19234
result:
ok 1 number(s): "19234"
Test #33:
score: 10
Accepted
time: 2ms
memory: 4440kb
input:
19 16 2 10
output:
77876
result:
ok 1 number(s): "77876"
Test #34:
score: 10
Accepted
time: 3ms
memory: 4472kb
input:
19 16 0
output:
301208
result:
ok 1 number(s): "301208"
Test #35:
score: 10
Accepted
time: 0ms
memory: 3864kb
input:
20 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #36:
score: 10
Accepted
time: 0ms
memory: 4076kb
input:
20 2 0
output:
2
result:
ok 1 number(s): "2"
Test #37:
score: 10
Accepted
time: 0ms
memory: 4080kb
input:
20 10 9 110111000
output:
76
result:
ok 1 number(s): "76"
Test #38:
score: 10
Accepted
time: 0ms
memory: 4084kb
input:
20 10 9 110101110
output:
372
result:
ok 1 number(s): "372"
Test #39:
score: 10
Accepted
time: 1ms
memory: 3960kb
input:
20 14 11 10110110000
output:
207
result:
ok 1 number(s): "207"
Test #40:
score: 10
Accepted
time: 1ms
memory: 4188kb
input:
20 14 7 0011011
output:
3675
result:
ok 1 number(s): "3675"
Test #41:
score: 10
Accepted
time: 14ms
memory: 12184kb
input:
20 20 14 10111010000000
output:
58
result:
ok 1 number(s): "58"
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #42:
score: 10
Accepted
time: 2ms
memory: 3996kb
input:
114 12 11 11010000010
output:
394940507
result:
ok 1 number(s): "394940507"
Test #43:
score: 10
Accepted
time: 3ms
memory: 3860kb
input:
114 12 2 01
output:
60509873
result:
ok 1 number(s): "60509873"
Test #44:
score: 10
Accepted
time: 5ms
memory: 3900kb
input:
114 14 10 1001111011
output:
154687039
result:
ok 1 number(s): "154687039"
Test #45:
score: 10
Accepted
time: 8ms
memory: 3972kb
input:
114 14 5 00100
output:
941826071
result:
ok 1 number(s): "941826071"
Test #46:
score: 10
Accepted
time: 29ms
memory: 4340kb
input:
114 16 10 1011101001
output:
391666362
result:
ok 1 number(s): "391666362"
Test #47:
score: 10
Accepted
time: 13ms
memory: 4472kb
input:
114 16 15 000010011111010
output:
599226561
result:
ok 1 number(s): "599226561"
Test #48:
score: 10
Accepted
time: 127ms
memory: 5880kb
input:
114 18 1 0
output:
167675624
result:
ok 1 number(s): "167675624"
Test #49:
score: 10
Accepted
time: 115ms
memory: 6012kb
input:
114 18 8 11000001
output:
165986235
result:
ok 1 number(s): "165986235"
Test #50:
score: 10
Accepted
time: 399ms
memory: 11972kb
input:
114 20 17 11101000010011010
output:
852476378
result:
ok 1 number(s): "852476378"
Test #51:
score: 10
Accepted
time: 419ms
memory: 12080kb
input:
114 20 13 1101011010000
output:
974712368
result:
ok 1 number(s): "974712368"
Test #52:
score: 10
Accepted
time: 2ms
memory: 3924kb
input:
113 12 8 10101100
output:
754580060
result:
ok 1 number(s): "754580060"
Test #53:
score: 10
Accepted
time: 0ms
memory: 3916kb
input:
113 12 10 1110010010
output:
928476173
result:
ok 1 number(s): "928476173"
Test #54:
score: 10
Accepted
time: 8ms
memory: 3896kb
input:
113 14 9 010111000
output:
930953494
result:
ok 1 number(s): "930953494"
Test #55:
score: 10
Accepted
time: 9ms
memory: 3916kb
input:
113 14 0
output:
613264431
result:
ok 1 number(s): "613264431"
Test #56:
score: 10
Accepted
time: 31ms
memory: 4288kb
input:
113 16 4 0011
output:
966491874
result:
ok 1 number(s): "966491874"
Test #57:
score: 10
Accepted
time: 30ms
memory: 4584kb
input:
113 16 10 1110110011
output:
71975445
result:
ok 1 number(s): "71975445"
Test #58:
score: 10
Accepted
time: 124ms
memory: 5888kb
input:
113 18 2 01
output:
35416931
result:
ok 1 number(s): "35416931"
Test #59:
score: 10
Accepted
time: 105ms
memory: 6120kb
input:
113 18 11 01101011111
output:
605684813
result:
ok 1 number(s): "605684813"
Test #60:
score: 10
Accepted
time: 476ms
memory: 12184kb
input:
113 20 1 1
output:
970488755
result:
ok 1 number(s): "970488755"
Test #61:
score: 10
Accepted
time: 407ms
memory: 12188kb
input:
113 20 17 10000001101111001
output:
308768022
result:
ok 1 number(s): "308768022"
Test #62:
score: 10
Accepted
time: 2ms
memory: 3992kb
input:
112 12 10 1011100000
output:
379472486
result:
ok 1 number(s): "379472486"
Test #63:
score: 10
Accepted
time: 2ms
memory: 3808kb
input:
112 12 3 111
output:
876338776
result:
ok 1 number(s): "876338776"
Test #64:
score: 10
Accepted
time: 8ms
memory: 3964kb
input:
112 14 6 100111
output:
850899867
result:
ok 1 number(s): "850899867"
Test #65:
score: 10
Accepted
time: 2ms
memory: 4020kb
input:
112 14 11 11011001011
output:
579315503
result:
ok 1 number(s): "579315503"
Test #66:
score: 10
Accepted
time: 28ms
memory: 4348kb
input:
112 16 11 00000111111
output:
827780781
result:
ok 1 number(s): "827780781"
Test #67:
score: 10
Accepted
time: 29ms
memory: 4344kb
input:
112 16 9 101001101
output:
247916257
result:
ok 1 number(s): "247916257"
Test #68:
score: 10
Accepted
time: 59ms
memory: 5880kb
input:
112 18 16 0011000001111001
output:
740632908
result:
ok 1 number(s): "740632908"
Test #69:
score: 10
Accepted
time: 118ms
memory: 5828kb
input:
112 18 4 0010
output:
594108528
result:
ok 1 number(s): "594108528"
Test #70:
score: 10
Accepted
time: 444ms
memory: 12256kb
input:
112 20 7 1010100
output:
818166882
result:
ok 1 number(s): "818166882"
Test #71:
score: 10
Accepted
time: 249ms
memory: 12160kb
input:
112 20 16 0001100100101000
output:
222914924
result:
ok 1 number(s): "222914924"
Test #72:
score: 10
Accepted
time: 0ms
memory: 3804kb
input:
111 12 2 11
output:
895626591
result:
ok 1 number(s): "895626591"
Test #73:
score: 10
Accepted
time: 2ms
memory: 3872kb
input:
111 12 1 1
output:
543447881
result:
ok 1 number(s): "543447881"
Test #74:
score: 10
Accepted
time: 8ms
memory: 4088kb
input:
111 14 3 111
output:
555958815
result:
ok 1 number(s): "555958815"
Test #75:
score: 10
Accepted
time: 4ms
memory: 3956kb
input:
111 14 13 1110001101010
output:
47749667
result:
ok 1 number(s): "47749667"
Test #76:
score: 10
Accepted
time: 26ms
memory: 4404kb
input:
111 16 5 01000
output:
880732287
result:
ok 1 number(s): "880732287"
Test #77:
score: 10
Accepted
time: 29ms
memory: 4288kb
input:
111 16 7 0110010
output:
153134396
result:
ok 1 number(s): "153134396"
Test #78:
score: 10
Accepted
time: 64ms
memory: 5876kb
input:
111 18 17 11011101001111100
output:
718197735
result:
ok 1 number(s): "718197735"
Test #79:
score: 10
Accepted
time: 109ms
memory: 5940kb
input:
111 18 9 011110101
output:
78875109
result:
ok 1 number(s): "78875109"
Test #80:
score: 10
Accepted
time: 442ms
memory: 12256kb
input:
111 20 6 100101
output:
484008568
result:
ok 1 number(s): "484008568"
Test #81:
score: 10
Accepted
time: 222ms
memory: 11968kb
input:
111 20 19 1100110110001010110
output:
612558978
result:
ok 1 number(s): "612558978"
Test #82:
score: 10
Accepted
time: 372ms
memory: 12020kb
input:
102 20 10 0101000100
output:
678899105
result:
ok 1 number(s): "678899105"
Test #83:
score: 10
Accepted
time: 19ms
memory: 4288kb
input:
97 16 13 0101110011010
output:
456291266
result:
ok 1 number(s): "456291266"
Subtask #3:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #84:
score: 30
Accepted
time: 210ms
memory: 12016kb
input:
66 20 5 11001
output:
286180948
result:
ok 1 number(s): "286180948"
Test #85:
score: 30
Accepted
time: 99ms
memory: 12260kb
input:
66 20 19 0101001111011100100
output:
334317215
result:
ok 1 number(s): "334317215"
Test #86:
score: 30
Accepted
time: 449ms
memory: 36536kb
input:
66 22 19 1001101100000100001
output:
465510840
result:
ok 1 number(s): "465510840"
Test #87:
score: 30
Accepted
time: 736ms
memory: 36624kb
input:
66 22 11 10001111000
output:
731812403
result:
ok 1 number(s): "731812403"
Test #88:
score: 0
Wrong Answer
time: 8ms
memory: 10948kb
input:
66 24 6 011111
output:
24 48 66 24 48 66 270615978
result:
wrong answer 1st numbers differ - expected: '270615978', found: '24'
Subtask #4:
score: 0
Time Limit Exceeded
Test #137:
score: 20
Accepted
time: 492ms
memory: 12084kb
input:
114 20 0
output:
849724285
result:
ok 1 number(s): "849724285"
Test #138:
score: 0
Time Limit Exceeded
input:
114 22 0
output:
918046462
result:
Subtask #5:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #3:
0%