Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define prm(x) x.begin(), x.end()
- #define srt(x) sort(prm(x))
- #define rvs(x) reverse(prm(x))
- using namespace std;
- using ll = long long;
- using ld = long double;
- vector<pair<ll, ll>> p;
- vector<ll> tp;
- void opt(vector<vector<pair<ll, ll>>> &v)
- {
- cout << endl;
- for (auto c1 : v)
- {
- for (auto c2 : c1)
- {
- if (c2.first == c2.second)
- {
- cout << c2.first << " ";
- }
- else
- {
- cout << c2.first << "/" << c2.second << " ";
- }
- }
- cout << endl;
- }
- }
- void vrfy2(vector<vector<pair<ll, ll>>> &v)
- {
- for (int i = 0; i < 6; i++)
- {
- string ax1 = "123456789";
- string ax2 = "123456789";
- for (int j = 0; j < 6; j++)
- {
- // part 1:
- ax1.at(v.at(i).at(j).first - 1) = '0';
- ax1.at(v.at(i).at(j).second - 1) = '0';
- // part 2:
- ax2.at(v.at(j).at(i).first - 1) = '0';
- ax2.at(v.at(j).at(i).second - 1) = '0';
- }
- if (ax1 != string(10, '0') || ax2 != string(10, '0'))
- {
- return;
- }
- }
- for (int i = 0; i < 6; i += 2)
- {
- for (int j = 0; j < 6; j += 3)
- {
- string ax = "123456789";
- for (int x = 0; x < 2; x++)
- {
- for (int y = 0; y < 3; y++)
- {
- ax.at(v.at(i + x).at(j + y).first - 1) = '0';
- ax.at(v.at(i + x).at(j + y).second - 1) = '0';
- }
- }
- if (ax != string(9, '0'))
- {
- return;
- }
- }
- }
- opt(v);
- }
- bool vrfy1(vector<vector<pair<ll, ll>>> &v, ll x, ll y, ll c)
- {
- if (v.at(x).at(y).first == c || v.at(x).at(y).second == c)
- {
- return false;
- }
- for (int i = 0; i < 6; i++)
- {
- if (v.at(x).at(i).first == c || v.at(x).at(i).second == c)
- {
- return false;
- }
- if (v.at(i).at(y).first == c || v.at(i).at(y).second == c)
- {
- return false;
- }
- }
- x = x / 2 + x / 2;
- y = (y / 3) * 3;
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (v.at(x + i).at(y + j).first == c)
- {
- return false;
- }
- }
- }
- return true;
- }
- void solve(vector<vector<pair<ll, ll>>> &v, ll c)
- {
- if (c == p.size())
- {
- vrfy2(v);
- return;
- }
- ll x = p.at(c).first;
- ll y = p.at(c).second;
- for (int i = 1; i <= 9; i++)
- {
- if (vrfy1(v, x, y, i))
- {
- if (tp.at(c) == 1)
- {
- v.at(x).at(y).first = i;
- solve(v, c + 1);
- v.at(x).at(y).first = 0;
- }
- else if (tp.at(c) == 2)
- {
- v.at(x).at(y).second = i;
- solve(v, c + 1);
- v.at(x).at(y).second = 0;
- }
- else
- {
- v.at(x).at(y).first = i;
- v.at(x).at(y).second = i;
- solve(v, c + 1);
- v.at(x).at(y).first = 0;
- v.at(x).at(y).second = 0;
- }
- }
- }
- }
- int main()
- {
- vector<vector<pair<ll, ll>>> v(6, vector<pair<ll, ll>>(6, {0, 0}));
- string ww;
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- ll n1 = 0, n2 = 0;
- cin >> ww;
- if (ww.size() == 3)
- {
- if (ww.at(0) != '-')
- {
- n1 = ww.at(0) - '0';
- }
- if (ww.at(2) != '-')
- {
- n2 = ww.at(2) - '0';
- }
- }
- else
- {
- if (ww != "-")
- {
- n1 = ww.front() - '0';
- n2 = ww.front() - '0';
- }
- }
- v.at(i).at(j) = {n1, n2};
- if (n1 == 0 && n2 == 0 && ww.size() == 1)
- {
- p.push_back({i, j});
- tp.push_back(3);
- }
- else
- {
- if (n1 == 0)
- {
- p.push_back({i, j});
- tp.push_back(1);
- }
- if (n2 == 0)
- {
- p.push_back({i, j});
- tp.push_back(2);
- }
- }
- }
- }
- solve(v, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement