Advertisement
xT30x

Untitled

Mar 16th, 2023 (edited)
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 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.     for (auto c1 : v)
  17.     {
  18.         for (auto c2 : c1)
  19.         {
  20.             if (c2.first == c2.second)
  21.             {
  22.                 cout << c2.first << " ";
  23.             }
  24.             else
  25.             {
  26.                 cout << c2.first << "/" << c2.second << " ";
  27.             }
  28.         }
  29.         cout << endl;
  30.     }
  31. }
  32.  
  33. bool vrfy1(vector<vector<pair<ll, ll>>> &v, ll x, ll y, ll c)
  34. {
  35.     if (v.at(x).at(y).first == c || v.at(x).at(y).second == c)
  36.     {
  37.         return false;
  38.     }
  39.     for (int i = 0; i < 6; i++)
  40.     {
  41.         if (v.at(x).at(i).first == c || v.at(x).at(i).second == c)
  42.         {
  43.             return false;
  44.         }
  45.         if (v.at(i).at(y).first == c || v.at(i).at(y).second == c)
  46.         {
  47.             return false;
  48.         }
  49.     }
  50.     x /= 2;
  51.     y /= 3;
  52.     for (int i = 0; i < 2; i++)
  53.     {
  54.         for (int j = 0; j < 3; j++)
  55.         {
  56.             if (v.at(x + i).at(y + j).first == c)
  57.             {
  58.                 return false;
  59.             }
  60.         }
  61.     }
  62.     return true;
  63. }
  64.  
  65. void solve(vector<vector<pair<ll, ll>>> &v, ll c)
  66. {
  67.  
  68.     if (c == p.size() - 1)
  69.     {
  70.         opt(v);
  71.         return;
  72.     }
  73.     ll x = p.at(c).first;
  74.     ll y = p.at(c).second;
  75.  
  76.     for (int i = 1; i <= 9; i++)
  77.     {
  78.         if (vrfy1(v, x, y, i))
  79.         {
  80.             if (tp.at(c) == 1)
  81.             {
  82.                 v.at(x).at(y).first = i;
  83.                 solve(v, c + 1);
  84.                 v.at(x).at(y).first = 0;
  85.             }
  86.             else if (tp.at(c) == 2)
  87.             {
  88.                 v.at(x).at(y).second = i;
  89.                 solve(v, c + 1);
  90.                 v.at(x).at(y).second = 0;
  91.             }
  92.             else
  93.             {
  94.                 v.at(x).at(y).first = i;
  95.                 v.at(x).at(y).second = i;
  96.                 solve(v, c + 1);
  97.                 v.at(x).at(y).first = 0;
  98.                 v.at(x).at(y).second = 0;
  99.             }
  100.         }
  101.     }
  102. }
  103. int main()
  104. {
  105.     vector<vector<pair<ll, ll>>> v(6, vector<pair<ll, ll>>(6, {0, 0}));
  106.     string ww;
  107.     for (int i = 0; i < 6; i++)
  108.     {
  109.         for (int j = 0; j < 6; j++)
  110.         {
  111.             ll n1 = 0, n2 = 0;
  112.             cin >> ww;
  113.             if (ww.size() == 3)
  114.             {
  115.  
  116.                 if (ww.at(0) != '-')
  117.                 {
  118.                     n1 = ww.at(0) - '0';
  119.                 }
  120.                 if (ww.at(2) != '-')
  121.                 {
  122.                     n2 = ww.at(2) - '0';
  123.                 }
  124.             }
  125.             else
  126.             {
  127.                 if (ww != "-")
  128.                 {
  129.                     n1 = ww.front() - '0';
  130.                     n2 = ww.front() - '0';
  131.                 }
  132.             }
  133.  
  134.             v.at(i).at(j) = {n1, n2};
  135.             if (n1 == 0 && n2 == 0)
  136.             {
  137.                 p.push_back({i, j});
  138.                 tp.push_back(3);
  139.             }
  140.             else if (n1 == 0)
  141.             {
  142.                 p.push_back({i, j});
  143.                 tp.push_back(1);
  144.             }
  145.             else if (n2 == 0)
  146.             {
  147.                 p.push_back({i, j});
  148.                 tp.push_back(2);
  149.             }
  150.         }
  151.     }
  152.     solve(v, 0);
  153.     return 0;
  154. }
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement