- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
#include <fstream>
using namespace std;
#define ES EXIT_SUCCESS
#define FOR(i___,___n) for (int i___=0; i___<(int)___n; i___++)
#define RFOR(i__,__n,_n) for (int i__=__n; i__>=_n; i__--)
#define or(i__,__s) fstream i__((char*)__s)
#define ow(i__,__s) ofstream i__((char*)__s)
#define MEM(a,b) a=new char[b]
#define MEM1(a,b) a=new char*[b]
#define RFOR1(i__,_i,__n,_n) for (int i__=__n, _i=_n; i__>=_n; i__--,_i++)
int N,L,D;
char **F, *W;
int main()
{
or(in,"input.txt"); ow(out,"output.txt");
in>>N>>L>>D;
MEM(W,N),MEM1(F,N+1), in.get();
FOR(i,N-L+1) W[i]='0';
FOR(i,L) W[N-L+i]=in.get();
FOR(i,N+1) MEM(F[i],2), F[i][0]=F[i][1]=0;
F[0][0]=1;
RFOR1(j,i,N-1,0)
if (W[j]=='0')
F[i+1][1]=F[i][1], F[i+1][0]=(F[i][0] + F[i][1])%D;
else
F[i+1][1]=(F[i][1] +F[i][0])%D, F[i+1][0]=F[i][0];
out<<(int)F[N][0];
return ES;
}