xT30x

Untitled

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