WA on #6
Can anyone give some test cases?
#include<bits/stdc++.h>
using namespace std;
int i, j, k, l, x, y, z, m, n, ans;
string first, second;
int dp[1010][1010][3][4], dir[1010][1010];
int make_way(int first_pile, int second_pile, char c, int state)
{
//cout << first_pile << ' ' << second_pile << endl;
if(first_pile == n && second_pile == n){
if(state > 1) return 0;
else return 1;
}
if(state > 1) return 0;
int p = 0, q = 0, r = 0;
char d;
if(c == '0') d = '1';
else d = '0';
if(first_pile < n){
if(first[first_pile] == c){
p = make_way(first_pile + 1, second_pile, c, state + 1);
}
else{
p = make_way(first_pile + 1, second_pile, d, 1);
}
}
if(second_pile < n){
if(second[second_pile] == c){
q = make_way(first_pile , second_pile + 1, c, state + 1);
}
else{
q = make_way(first_pile , second_pile + 1, d, 1);
}
}
if(p == 1){
dir[first_pile][second_pile] = 1;
}
else if(q == 1) dir[first_pile][second_pile] = 2;
dp[first_pile][second_pile][c - '0'][state] = p | q;
return dp[first_pile][second_pile][c - '0'][state];
}
int main()
{
cin >> n >> first >> second;
ans = make_way(0, 0, '0', 0);
if(!ans){
cout << "Impossible" ;
return 0;
}
for(i = 0, j = 0; i < n || j < n; ){
cout << dir[i][j];
if(dir[i][j] == 1) i++;
else j++;
}
return 0;
}