QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293820 | #4893. Imbalance | ucup-team1004 | 20 | 1449ms | 52784kb | C++14 | 3.8kb | 2023-12-29 19:59:42 | 2023-12-29 19:59:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) begin(a),end(a)
#ifdef DEBUG
template<class T>
ostream& operator << (ostream &out,vector<T> a){
out<<'[';
for(T x:a)out<<x<<',';
return out<<']';
}
template<class T>
vector<T> ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<class T>
void debug(T x){
cerr<<x<<endl;
}
template<class T,class...S>
void debug(T x,S...y){
cerr<<x<<' ',debug(y...);
}
#else
#define debug(...) void()
#endif
const int N=120,mod=998244353;
int n,k,m;
char a[N];
namespace Solve1{
const int K=22,M=1<<K;
int f[2][M],cnt[M];
void add(int &x,int y){
(x+=y)>=mod&&(x-=mod);
}
void solve(){
int S=0,now=1,las=0,U=(1<<k-1)-1;
for(int S=0;S<=U*2;S++)cnt[S]=__builtin_popcount(S);
for(int i=1;i<=m;i++){
S|=(a[i]&1)<<(i+k-m-1);
}
f[now][S]=1;
for(int i=m+1;i<=n;i++){
swap(now,las);
memset(f[now],0,sizeof f[now]);
for(int S=0;S<=U;S++)if(f[las][S]){
for(int x:{0,1}){
int T=(S|(x<<k-1))>>1;
if(i<k||cnt[S|(x<<k-1)]!=k/2)add(f[now][T],f[las][S]);
}
}
}
cout<<accumulate(f[now],f[now]+1+U,0ll)%mod<<endl;
debug(1.0*clock()/CLOCKS_PER_SEC);
exit(0);
}
}
const int M=6;
using matrix=array<array<int,M>,M>;
#ifdef DEBUG
ostream& operator << (ostream &out,matrix a){
vector<vector<int>>p;
for(auto x:a){
vector<int>t;
for(int y:x)t.push_back(y);
p.push_back(t);
}
return out<<p;
}
#endif
namespace Solve2{
int ans,lim,sx,sy,tx,ty,H;
int ban[N][N],f[N][N][N],g[N][N];
int det(matrix &a,int m){
int ans=1;
for(int i=0;i<=m;i++){
for(int j=i+1;j<=m;j++){
for(;a[i][i];a[i].swap(a[j]),ans=-ans){
int x=mod-a[j][i]/a[i][i];
for(int k=0;k<=m;k++)a[j][k]=(a[j][k]+1ll*x*a[i][k])%mod;
}
a[i].swap(a[j]),ans=-ans;
}
}
for(int i=0;i<=m;i++)ans=1ll*ans*a[i][i]%mod;
return (ans+mod)%mod;
}
int cnt,s[M];
void dfs(int x){
if(x==n/k+1){
static matrix a;
for(int i=0;i<=n/k;i++){
for(int j=0;j<=n/k;j++){
if(i&&j<n/k){
a[i][j]=f[lim*(i+1)-s[i]][lim*(j+1)-s[j+1]][k];
}else if(i){
a[i][j]=f[lim*(i+1)-s[i]][tx][ty];
}else if(j<n/k){
a[i][j]=g[lim*(j+1)-s[j+1]][k];
}else{
a[i][j]=g[tx][ty];
}
}
}
int res=det(a,n/k);
// if(res)debug(cnt,ary(s,0,x-1),a,res);
(ans+=res)%=mod;
return;
}
for(s[x]=s[x-1];s[x]<s[x-1]+lim&&s[x]<=cnt;s[x]++)dfs(x+1);
}
void calc(){
lim=k/2,sx=lim,sy=0;
for(int i=0;i<m;i++){
ban[sx][sy++]=1,sx-=a[i+1]&1;
if(sx<0)return;
}
ban[sx][sy]=1;
H=lim*(n/k+1);
for(int i=H;i>=0;i--){
for(int j=k;j>=0;j--){
ban[i][j]|=ban[i+1][j]|ban[i][j+1];
}
}
for(int i=0;i<=H;i++)debug(ary(ban[i],0,k));
for(cnt=0;cnt<=n/k*lim+min(lim,n%k);cnt++){
tx=lim*(n/k+1)-cnt,ty=n%k;
if(cnt==15)debug(tx,ty,"ok");
if(ban[tx][ty])continue;
for(int i=tx;i<=H;i++){
for(int j=ty;j<=k;j++)ban[i][j]=i>tx||j>ty;
}
memset(g,0,sizeof g);
memset(f,0,sizeof f);
g[sx][sy]=1;
for(int i=sx;~i;i--){
for(int j=sy+1;j<=k;j++)if(!ban[i][j]){
g[i][j]=(g[i+1][j-1]+g[i][j-1])%mod;
}
}
for(int s=0;s<=H;s++){
f[s][s][0]=1;
for(int i=s;~i;i--){
for(int j=1;j<=k;j++)if(!ban[i][j]){
f[s][i][j]=(f[s][i+1][j-1]+f[s][i][j-1])%mod;
}
}
}
// debug(tx,ty);
dfs(1);
for(int i=tx;i<=H;i++){
for(int j=ty;j<=k;j++)ban[i][j]=0;
}
}
}
void solve(){
calc();
debug("rev");
for(int i=1;i<=m;i++)a[i]^=1;
memset(ban,0,sizeof ban);
calc();
cout<<ans<<endl;
debug(1.0*clock()/CLOCKS_PER_SEC);
exit(0);
}
}
int main(){
scanf("%d%d%d%s",&n,&k,&m,a+1);
if(k<=Solve1::K)Solve1::solve();
Solve2::solve();
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 4ms
memory: 36396kb
input:
2 2 0
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 19884kb
input:
2 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 8ms
memory: 36408kb
input:
3 2 0
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 7ms
memory: 36408kb
input:
3 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 3ms
memory: 36404kb
input:
4 2 0
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 36264kb
input:
4 2 1 0
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 4ms
memory: 36260kb
input:
4 4 0
output:
10
result:
ok 1 number(s): "10"
Test #8:
score: -10
Wrong Answer
time: 3ms
memory: 36388kb
input:
4 4 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '5', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 20
Accepted
Test #137:
score: 20
Accepted
time: 236ms
memory: 40508kb
input:
114 20 0
output:
849724285
result:
ok 1 number(s): "849724285"
Test #138:
score: 0
Accepted
time: 623ms
memory: 52784kb
input:
114 22 0
output:
918046462
result:
ok 1 number(s): "918046462"
Test #139:
score: 0
Accepted
time: 1033ms
memory: 10352kb
input:
114 24 0
output:
471169566
result:
ok 1 number(s): "471169566"
Test #140:
score: 0
Accepted
time: 1449ms
memory: 10412kb
input:
114 26 0
output:
540055361
result:
ok 1 number(s): "540055361"
Test #141:
score: 0
Accepted
time: 1309ms
memory: 10348kb
input:
114 28 0
output:
997530597
result:
ok 1 number(s): "997530597"
Test #142:
score: 0
Accepted
time: 165ms
memory: 10348kb
input:
114 30 0
output:
37439521
result:
ok 1 number(s): "37439521"
Test #143:
score: 0
Accepted
time: 214ms
memory: 10492kb
input:
114 32 0
output:
448438493
result:
ok 1 number(s): "448438493"
Test #144:
score: 0
Accepted
time: 226ms
memory: 40416kb
input:
113 20 0
output:
942733157
result:
ok 1 number(s): "942733157"
Test #145:
score: 0
Accepted
time: 610ms
memory: 52764kb
input:
113 22 0
output:
547536565
result:
ok 1 number(s): "547536565"
Test #146:
score: 0
Accepted
time: 1045ms
memory: 10360kb
input:
113 24 0
output:
219952878
result:
ok 1 number(s): "219952878"
Test #147:
score: 0
Accepted
time: 1373ms
memory: 10492kb
input:
113 26 0
output:
763274765
result:
ok 1 number(s): "763274765"
Test #148:
score: 0
Accepted
time: 1230ms
memory: 10412kb
input:
113 28 0
output:
910952876
result:
ok 1 number(s): "910952876"
Test #149:
score: 0
Accepted
time: 169ms
memory: 10528kb
input:
113 30 0
output:
968408969
result:
ok 1 number(s): "968408969"
Test #150:
score: 0
Accepted
time: 221ms
memory: 10396kb
input:
113 32 0
output:
118567934
result:
ok 1 number(s): "118567934"
Test #151:
score: 0
Accepted
time: 245ms
memory: 40412kb
input:
112 20 0
output:
275087743
result:
ok 1 number(s): "275087743"
Test #152:
score: 0
Accepted
time: 609ms
memory: 52764kb
input:
112 22 0
output:
185644824
result:
ok 1 number(s): "185644824"
Test #153:
score: 0
Accepted
time: 1027ms
memory: 10472kb
input:
112 24 0
output:
557785519
result:
ok 1 number(s): "557785519"
Test #154:
score: 0
Accepted
time: 1313ms
memory: 10416kb
input:
112 26 0
output:
522996775
result:
ok 1 number(s): "522996775"
Test #155:
score: 0
Accepted
time: 1112ms
memory: 10356kb
input:
112 28 0
output:
134122652
result:
ok 1 number(s): "134122652"
Test #156:
score: 0
Accepted
time: 163ms
memory: 10492kb
input:
112 30 0
output:
502459554
result:
ok 1 number(s): "502459554"
Test #157:
score: 0
Accepted
time: 210ms
memory: 10476kb
input:
112 32 0
output:
169309797
result:
ok 1 number(s): "169309797"
Test #158:
score: 0
Accepted
time: 225ms
memory: 40504kb
input:
111 20 0
output:
360310827
result:
ok 1 number(s): "360310827"
Test #159:
score: 0
Accepted
time: 605ms
memory: 52644kb
input:
111 22 0
output:
516490684
result:
ok 1 number(s): "516490684"
Test #160:
score: 0
Accepted
time: 1024ms
memory: 10420kb
input:
111 24 0
output:
501679698
result:
ok 1 number(s): "501679698"
Test #161:
score: 0
Accepted
time: 1257ms
memory: 10416kb
input:
111 26 0
output:
43788136
result:
ok 1 number(s): "43788136"
Test #162:
score: 0
Accepted
time: 145ms
memory: 10404kb
input:
111 28 0
output:
5764962
result:
ok 1 number(s): "5764962"
Test #163:
score: 0
Accepted
time: 164ms
memory: 10348kb
input:
111 30 0
output:
918617250
result:
ok 1 number(s): "918617250"
Test #164:
score: 0
Accepted
time: 221ms
memory: 10408kb
input:
111 32 0
output:
982496307
result:
ok 1 number(s): "982496307"
Test #165:
score: 0
Accepted
time: 344ms
memory: 10416kb
input:
114 114 0
output:
321821768
result:
ok 1 number(s): "321821768"
Test #166:
score: 0
Accepted
time: 105ms
memory: 10404kb
input:
114 50 0
output:
860957763
result:
ok 1 number(s): "860957763"
Test #167:
score: 0
Accepted
time: 101ms
memory: 10412kb
input:
113 50 0
output:
307614098
result:
ok 1 number(s): "307614098"
Test #168:
score: 0
Accepted
time: 88ms
memory: 36408kb
input:
110 10 0
output:
615608372
result:
ok 1 number(s): "615608372"
Test #169:
score: 0
Accepted
time: 77ms
memory: 10484kb
input:
100 50 0
output:
475715516
result:
ok 1 number(s): "475715516"
Test #170:
score: 0
Accepted
time: 158ms
memory: 10492kb
input:
111 78 0
output:
617855013
result:
ok 1 number(s): "617855013"
Test #171:
score: 0
Accepted
time: 103ms
memory: 10476kb
input:
100 26 0
output:
960228335
result:
ok 1 number(s): "960228335"
Test #172:
score: 0
Accepted
time: 141ms
memory: 10488kb
input:
99 28 0
output:
17612739
result:
ok 1 number(s): "17612739"
Test #173:
score: 0
Accepted
time: 138ms
memory: 10408kb
input:
107 28 0
output:
462764365
result:
ok 1 number(s): "462764365"
Subtask #5:
score: 0
Skipped
Dependency #2:
0%