QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#811408 | #7129. Independent set | Aurore | AC ✓ | 598ms | 438380kb | C++23 | 1.5kb | 2024-12-12 19:07:45 | 2024-12-12 19:07:51 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[105];
inline void print(int x,char ch=' '){
if(x<0) putchar('-'),x=-x;
int tot=0;
do{
buf[++tot]=x%10;
x/=10;
}while(x);
for(int i=tot;i;i--) putchar(buf[i]+'0');
putchar(ch);
}
const int MAXN=5e6+5,mod=1e9+7;
int n,m;
char s[MAXN];
int dp[MAXN][11][2];
void dfs(int x){
if(x*2>n){
dp[x][0][0]=1;
if(s[x]=='0'){
for(int i=1;i<=m;i++) dp[x][i][1]=1;
}
}
else if(x*2+1>n){
dfs(x*2);
if(s[x]=='0'){
for(int i=1;i<=m;i++)
dp[x][i][1]=(dp[x][i-1][1]+dp[x*2][i-1][0])%mod;
}
for(int i=0;i<=m;i++)
dp[x][i][0]=(dp[x*2][i][0]+dp[x*2][i][1])%mod;
}
else{
dfs(x*2),dfs(x*2+1);
//val[x]=0
for(int i=0;i<=m;i++){
long long sum=0;
for(int j=0;j<=i;j++){
int p=(dp[x*2][j][0]+dp[x*2][j][1])%mod;
int q=(dp[x*2+1][i-j][0]+dp[x*2+1][i-j][1])%mod;
sum=(sum+1ll*p*q);
}
sum%=mod;
dp[x][i][0]=sum;
}
//val[x]!=0
if(s[x]=='0'){
for(int i=0;i<m;i++){
long long sum=0;
for(int j=0;j<=i;j++)
sum=(sum+1ll*dp[x*2][j][0]*dp[x*2+1][i-j][0]);
sum%=mod;
dp[x][i+1][1]=(dp[x][i][1]+sum)%mod;
}
}
}
}
signed main(){
n=read(),m=read();
scanf("%s",s+1);
dfs(1);
print((dp[1][m][0]+dp[1][m][1])%mod);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5660kb
input:
2 2 00
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
10 3 0101010101
output:
26
result:
ok 1 number(s): "26"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5596kb
input:
10 3 0000100000
output:
110
result:
ok 1 number(s): "110"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5664kb
input:
10 3 0001000000
output:
117
result:
ok 1 number(s): "117"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
10 3 0010000001
output:
86
result:
ok 1 number(s): "86"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
10 3 0100000000
output:
115
result:
ok 1 number(s): "115"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5792kb
input:
10 3 0010000000
output:
118
result:
ok 1 number(s): "118"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
10 3 1011001000
output:
45
result:
ok 1 number(s): "45"
Test #9:
score: 0
Accepted
time: 0ms
memory: 5872kb
input:
10 3 0000011001
output:
49
result:
ok 1 number(s): "49"
Test #10:
score: 0
Accepted
time: 0ms
memory: 5620kb
input:
10 3 0000010011
output:
48
result:
ok 1 number(s): "48"
Test #11:
score: 0
Accepted
time: 0ms
memory: 5852kb
input:
10 3 0100100101
output:
35
result:
ok 1 number(s): "35"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5808kb
input:
10 3 0000000011
output:
72
result:
ok 1 number(s): "72"
Test #13:
score: 0
Accepted
time: 0ms
memory: 5868kb
input:
1000 10 0000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
876560614
result:
ok 1 number(s): "876560614"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
1000 10 0000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000010000000000000000000000000000000100000000000000010000000000000000000000001000000010000001000000000000000000000000000000000000000000000000000000000000...
output:
45119364
result:
ok 1 number(s): "45119364"
Test #15:
score: 0
Accepted
time: 1ms
memory: 5872kb
input:
1000 10 1100000010000000000010011100000000001000001101001010010000100100001000000000001010010100100000001001000000000000000010000010000001010000000000100000100000000000010100010000110000010010001000000000001000001000000000010001011010000000100100000000001010001110000010000000000000000000000000000000...
output:
460336587
result:
ok 1 number(s): "460336587"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5816kb
input:
1000 10 0000000100000001000010001100000000000100000011000000000110100111000000100000000001000000000100100100010010011000010000010010001000100100000000000000100000100000010000000100000000000100001000000000000000000010000000001000010001000000010010000000000000000000100001000100000001000010100100011010...
output:
48086189
result:
ok 1 number(s): "48086189"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5832kb
input:
1000 10 0010000000001000000001011000000000000000000000000000000000000001000010000001011000000000000000000000000000000010000010010000010000100001000001000000110000000000000100000000000000001001000000001000000001010000001001000000000000000000000000000000000010000000000010000001100001000000000100000110...
output:
512493587
result:
ok 1 number(s): "512493587"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5940kb
input:
1000 10 0000000010000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000...
output:
412295689
result:
ok 1 number(s): "412295689"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5708kb
input:
1000 10 0000100111000011101000000000010110000001100001100100000000000000001001000000010000100000010000010000000000100000000001000001000000010000000000110000100001000000001010010000000000110101100000100000101000110100001001000000101000000000000000010000001000100000000100001001010010010001000000000000...
output:
518455593
result:
ok 1 number(s): "518455593"
Test #20:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
1000 10 0000000100000000001000000000000000000000000000000001000000000000000010000000000010000000000000000000000000100100010000000110000000000000000000000000000010000000000000100000000100000000000000000000100010000000000100000000010010001000000000000000000000000000000000000000000000000000001000010000...
output:
430339412
result:
ok 1 number(s): "430339412"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
1000 10 0000110010000000000010101001010000100010010110000100001000100001000000000010000100000011100000000000010100001000000000000000100000100001100000001000000111100000100101001000000000000000001000001000100000000010000000001000001000000000001000000000000000001000100100001100100000011010001000000011...
output:
348316472
result:
ok 1 number(s): "348316472"
Test #22:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
1000 10 0000100000000010000000000000000000000000000000000001000010000010001010010000000000000000100100100100101101001001010000100000000000100000000000000100001010011100000001000000000010000000001000001001000001010001001000000010000000110000010000000000000000000101000001100000100000100000001010001000...
output:
213483490
result:
ok 1 number(s): "213483490"
Test #23:
score: 0
Accepted
time: 103ms
memory: 93212kb
input:
1000000 10 1000000000100011011000001001000100000111000100001001000000000000000000000010100000010000000000000001100110010100011010001000100100001101010010101100001100100110001100010001000000000000011000001000010100000100000110001101000000000100110000100000100001000010000001000010000100001000000011110...
output:
476845308
result:
ok 1 number(s): "476845308"
Test #24:
score: 0
Accepted
time: 105ms
memory: 93772kb
input:
1000000 10 0000000000000000000000000000000001000000100000000000000000000000000000000000000000000100000000010000000010000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000100001010000000000000000000000000000000000000000000000000100000010000100000010...
output:
774002748
result:
ok 1 number(s): "774002748"
Test #25:
score: 0
Accepted
time: 104ms
memory: 92428kb
input:
1000000 10 0000000000000000000001000000010000010010100110110001000100010000100000000111001000000000000001010000101000000000011000101000100000000000000000000000110010000000111001010000000000010000110000000100100000000001001001001001000010010001010000000000000000100001000000000000001100000100000000000...
output:
160255662
result:
ok 1 number(s): "160255662"
Test #26:
score: 0
Accepted
time: 106ms
memory: 95744kb
input:
1000000 10 0000000010000000000000100000000000000010000100001000000000000000000000100000100000000000000000000000000000100000000000000000011000000011000000001010000000000011000010111000010000000000000000000010000000000000000010000000000000000000010000010000100000001000000000000000010001000001000000000...
output:
707886122
result:
ok 1 number(s): "707886122"
Test #27:
score: 0
Accepted
time: 101ms
memory: 93724kb
input:
1000000 10 0100100000000000000000000000000100000000000100100000000000010000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000011000000000000000000000000000010000000000000000000000100000100000000000000000000000000000000000010000100000010000000000000000...
output:
979709914
result:
ok 1 number(s): "979709914"
Test #28:
score: 0
Accepted
time: 531ms
memory: 438136kb
input:
5000000 10 0000000000000000001000000000010000001000000000000000001000010000000000000000000000000000000000000000000000000000000000100000000000000000010001000000100000000000011000000000000000000001000000001000000000000000000000000000000000000000000000000001000000000000000000000001000100010000000001000...
output:
285627161
result:
ok 1 number(s): "285627161"
Test #29:
score: 0
Accepted
time: 555ms
memory: 438380kb
input:
5000000 10 0000000000000000000010000000010000000010000000000000000000000000000000000000000000000010000000000000000000000000001000000000000100000000000010000000000000000011000000000000000000000000000000000000000000000000000000000000000000010000000000000000010100100000010000000000000000000010000000000...
output:
303121972
result:
ok 1 number(s): "303121972"
Test #30:
score: 0
Accepted
time: 549ms
memory: 438376kb
input:
5000000 10 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
840451042
result:
ok 1 number(s): "840451042"
Test #31:
score: 0
Accepted
time: 520ms
memory: 438320kb
input:
5000000 10 0001001100000000000000000000000001000000000000010000000011000000000000000000000000010000000000000000000000000001001010000000100000000000000100000000000010101000010000010001000100000100000000000101000000010000000001010010000000000010100000000010000011000000000000000000000000000001000000000...
output:
5553929
result:
ok 1 number(s): "5553929"
Test #32:
score: 0
Accepted
time: 598ms
memory: 438368kb
input:
5000000 10 0000000000000000010000000000000000000000010000000000001000010100010010000110000000000000100010000000000000100000000000000010000000000000100000000000001100000000000000000000000000000100000000000000000000000000001010000000000100100000000000000000000000001000010100100011000000000000000000001...
output:
996917998
result:
ok 1 number(s): "996917998"