Advertisement
xT30x

Untitled

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