Advertisement
xT30x

Untitled

Mar 17th, 2023 (edited)
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define prm(x) x.begin(), x.end()
  4. #define srt(x) sort(prm(x))
  5. #define rvs(x) reverse(prm(x))
  6.  
  7. using namespace std;
  8. using ll = long long;
  9. using ld = long double;
  10.  
  11. vector<pair<ll, ll>> p;
  12. vector<ll> tp;
  13.  
  14. void opt(vector<vector<pair<ll, ll>>> &v)
  15. {
  16.     cout << endl;
  17.     for (auto c1 : v)
  18.     {
  19.         for (auto c2 : c1)
  20.         {
  21.             if (c2.first == c2.second)
  22.             {
  23.                 cout << c2.first << " ";
  24.             }
  25.             else
  26.             {
  27.                 cout << c2.first << "/" << c2.second << " ";
  28.             }
  29.         }
  30.         cout << endl;
  31.     }
  32. }
  33.  
  34. void vrfy2(vector<vector<pair<ll, ll>>> &v)
  35. {
  36.     for (int i = 0; i < 6; i++)
  37.     {
  38.         string ax1 = "123456789";
  39.         string ax2 = "123456789";
  40.  
  41.         for (int j = 0; j < 6; j++)
  42.         {
  43.             // part 1:
  44.  
  45.             ax1.at(v.at(i).at(j).first - 1) = '0';
  46.             ax1.at(v.at(i).at(j).second - 1) = '0';
  47.  
  48.             // part 2:
  49.  
  50.             ax2.at(v.at(j).at(i).first - 1) = '0';
  51.             ax2.at(v.at(j).at(i).second - 1) = '0';
  52.         }
  53.         if (ax1 != string(10, '0') || ax2 != string(10, '0'))
  54.         {
  55.             return;
  56.         }
  57.     }
  58.  
  59.     for (int i = 0; i < 6; i += 2)
  60.     {
  61.         for (int j = 0; j < 6; j += 3)
  62.         {
  63.             string ax = "123456789";
  64.             for (int x = 0; x < 2; x++)
  65.             {
  66.                 for (int y = 0; y < 3; y++)
  67.                 {
  68.                     ax.at(v.at(i + x).at(j + y).first - 1) = '0';
  69.                     ax.at(v.at(i + x).at(j + y).second - 1) = '0';
  70.                 }
  71.             }
  72.             if (ax != string(9, '0'))
  73.             {
  74.                 return;
  75.             }
  76.         }
  77.     }
  78.  
  79.     opt(v);
  80. }
  81.  
  82. bool vrfy1(vector<vector<pair<ll, ll>>> &v, ll x, ll y, ll c)
  83. {
  84.     if (v.at(x).at(y).first == c || v.at(x).at(y).second == c)
  85.     {
  86.         return false;
  87.     }
  88.     for (int i = 0; i < 6; i++)
  89.     {
  90.         if (v.at(x).at(i).first == c || v.at(x).at(i).second == c)
  91.         {
  92.             return false;
  93.         }
  94.         if (v.at(i).at(y).first == c || v.at(i).at(y).second == c)
  95.         {
  96.             return false;
  97.         }
  98.     }
  99.     x = x / 2 + x / 2;
  100.     y = (y / 3) * 3;
  101.     for (int i = 0; i < 2; i++)
  102.     {
  103.         for (int j = 0; j < 3; j++)
  104.         {
  105.             if (v.at(x + i).at(y + j).first == c)
  106.             {
  107.                 return false;
  108.             }
  109.         }
  110.     }
  111.     return true;
  112. }
  113.  
  114. void solve(vector<vector<pair<ll, ll>>> &v, ll c)
  115. {
  116.  
  117.     if (c == p.size())
  118.     {
  119.         vrfy2(v);
  120.         return;
  121.     }
  122.     ll x = p.at(c).first;
  123.     ll y = p.at(c).second;
  124.  
  125.     for (int i = 1; i <= 9; i++)
  126.     {
  127.         if (vrfy1(v, x, y, i))
  128.         {
  129.             if (tp.at(c) == 1)
  130.             {
  131.                 v.at(x).at(y).first = i;
  132.                 solve(v, c + 1);
  133.                 v.at(x).at(y).first = 0;
  134.             }
  135.             else if (tp.at(c) == 2)
  136.             {
  137.                 v.at(x).at(y).second = i;
  138.                 solve(v, c + 1);
  139.                 v.at(x).at(y).second = 0;
  140.             }
  141.             else
  142.             {
  143.                 v.at(x).at(y).first = i;
  144.                 v.at(x).at(y).second = i;
  145.                 solve(v, c + 1);
  146.                 v.at(x).at(y).first = 0;
  147.                 v.at(x).at(y).second = 0;
  148.             }
  149.         }
  150.     }
  151. }
  152. int main()
  153. {
  154.     vector<vector<pair<ll, ll>>> v(6, vector<pair<ll, ll>>(6, {0, 0}));
  155.     string ww;
  156.     for (int i = 0; i < 6; i++)
  157.     {
  158.         for (int j = 0; j < 6; j++)
  159.         {
  160.             ll n1 = 0, n2 = 0;
  161.             cin >> ww;
  162.             if (ww.size() == 3)
  163.             {
  164.  
  165.                 if (ww.at(0) != '-')
  166.                 {
  167.                     n1 = ww.at(0) - '0';
  168.                 }
  169.                 if (ww.at(2) != '-')
  170.                 {
  171.                     n2 = ww.at(2) - '0';
  172.                 }
  173.             }
  174.             else
  175.             {
  176.                 if (ww != "-")
  177.                 {
  178.                     n1 = ww.front() - '0';
  179.                     n2 = ww.front() - '0';
  180.                 }
  181.             }
  182.  
  183.             v.at(i).at(j) = {n1, n2};
  184.             if (n1 == 0 && n2 == 0 && ww.size() == 1)
  185.             {
  186.                 p.push_back({i, j});
  187.                 tp.push_back(3);
  188.             }
  189.             else
  190.             {
  191.                 if (n1 == 0)
  192.                 {
  193.                     p.push_back({i, j});
  194.                     tp.push_back(1);
  195.                 }
  196.                 if (n2 == 0)
  197.                 {
  198.                     p.push_back({i, j});
  199.                     tp.push_back(2);
  200.                 }
  201.             }
  202.         }
  203.     }
  204.     solve(v, 0);
  205.     return 0;
  206. }
  207.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement