Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define _CRT_DISABLE_PERFCRIT_LOCKS
- #include <iostream>
- #include<algorithm>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<bitset>
- using namespace std;
- typedef long long ll;
- const ll IN = ll(1e9);
- vector<int> w;
- int n, a;
- ll test(bitset<20> a) {
- ll s = 0;
- for (int j = 0; j < n; j++) {
- if (a[j])
- s += w[j];
- else
- s -= w[j];
- }
- return abs(s);
- }
- ll binpow(int a, int n) {
- if (n == 0)
- return 1;
- if (n % 2 == 1)
- return binpow(a, n - 1) * a;
- else {
- ll b = binpow(a, n / 2);
- return b * b;
- }
- }
- string ans = "";
- string a1 = "";
- string a2 = "";
- vector<vector<int>> temp(1001, vector<int>(1001, 2));
- int Solve(int a, int b, int x, int y) {
- if (x >= n && y >= n) {
- return 1;
- }
- if (temp[x][y] == 2) {
- if (abs(a - b) > 1) {
- temp[x][y] = 0;
- return 0;
- }
- else {
- int t1 = 0;
- if (x < n) {
- if (a1[x] == '1')
- t1 = Solve(a, b + 1, x + 1, y);
- else
- t1 = Solve(a + 1, b, x + 1, y);
- }
- if (t1) {
- ans += "1";
- return 1;
- }
- int t2 = 0;
- if (y < n) {
- if (a2[y] == '1')
- t2 = Solve(a, b + 1, x, y + 1);
- else
- t2 = Solve(a + 1, b, x, y + 1);
- }
- if (t2) {
- ans += "2";
- return 1;
- }
- temp[x][y] = 0;
- return 0;
- }
- }
- else
- return temp[x][y];
- }
- int main()
- {
- cin >> n;
- cin >> a1;
- cin >> a2;
- bool s = Solve(0, 0, 0, 0);
- if (s) {
- reverse(ans.begin(), ans.end());
- cout << ans;
- }
- else
- cout << "Impossible";
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement