In my compiler (Code::blocks 8.02) my code runs well & i got correct answer too for Test#79 but i got
"RUNTIME_ERROR" when i had submitted.
Can anyone say whats the problem in my code ?
Please help.....
Test#79
100 2
aa
000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
Here is my code (what I had submitted).
#include <iostream>
#include <string>
#include <cstdio>
#include <stdlib.h>
#include <string.h>
using namespace std;
#ifdef __GNUC__
typedef long long ll;typedef unsigned long long ull;
#else
typedef __int64 ll; typedef unsigned __int64 ull;
#endif
#define REP(i,n) for(i=0;i<n;i++)
#define REV(i,n) for(i=n;i>=0;i--)
#define FOR(i,x,y) for(i=(x);i<=(y);i++)
#define mem(x,with) memset(x,(with),sizeof(x))
#define SZ(x) (int)x.size()
int main()
{
int i,j,k,n,l,cnt[200],q;
char x[200];
string str,bit,m,m1,s;
bool apple;
while(cin>>n>>q)
{
apple=1;
cin>>str>>bit;
l=SZ(str);
mem(x,'0');
REP(i,SZ(bit))
{
if(bit[i]-'0')
{
k=0;
FOR(j,i,i+l-1)
{
x[j]=str[k];
k++;
}
}
}
REP(i,SZ(bit))
{
if(bit[i]-'0')
{
k=i;
s="";
REP(j,l)
{
s+=x[k];
k++;
}
if(s!=str)
apple=0;
}
}
mem(cnt,0);
REP(i,l)
{
cnt[str[i]]++;
}
if(l==1)
{
REP(i,n)
if(x[i]=='0')
FOR(j,97,(97+q-1))
if(!cnt[j])
{
x[i]=j;
break;
}
goto zaf;
}
m=str[0]+str[1];
REP(i,n)
{
if(i==0 && x[i]=='0')
{
FOR(j,97,97+q-1)
if(j!=str[j])
x[i]=j;
}
else if(x[i]=='0')
{
FOR(j,97,97+q-1)
{
m1=x[i-1]+j;
if(m1!=m)
x[i]=j;
}
}
}
zaf:
;
REP(i,SZ(bit))
{
if((bit[i]-'0')==0)
{
k=i;
s="";
REP(j,l)
{
s+=x[k];
k++;
}
if(s==str)
apple=0;
}
}
REP(i,n)
if(x[i]=='0')
apple=0;
if(!apple)
cout<<"No solution"<<endl;
else
{
REP(i,n)
cout<<x[i];
cout<<endl;
}
}
return 0;
}