fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define fi first
  4. #define si second
  5. #define For(i,a,b) for (int i = (a), _b =(b); i <= _b; ++i)
  6. #define all(v) v.begin(), v.end()
  7. #define Unique(v) v.erase(unique(all(v)), v.end())
  8. #define MASK(i) (1LL << (i))
  9. #define bit(i,n) (((n)>>(i)) & 1)
  10. #define Vii vector<pair<int,int>>
  11. #define setpr(x) cout<<setprecision(x)<<fixed
  12. #define Prior priority_queue<pair<int,int>, Vii, greater<pair<int,int>>>
  13.  
  14. using namespace std;
  15.  
  16. const int Mod = 1E9 + 7;
  17. const long long INF = 4E18;
  18. const int N = 100 + 1;
  19.  
  20. int d[6][2] = {{1, 2}, {2, 3}, {6, 7}, {9, 10}, {8, 9}, {4, 5}};
  21. queue<pair<array<int, 11>, int>> q;
  22. array<int, 11> arr;
  23. map<array<int, 11>, bool> vis;
  24.  
  25. signed main() {
  26. For(i, 1, 10) cin >> arr[i];
  27.  
  28. q.push({arr, 0});
  29.  
  30. while (!q.empty()) {
  31. pair<array<int, 11>, int> node = q.front();
  32. q.pop();
  33.  
  34. bool ok = true;
  35. For(i, 1, 3) if (node.fi[i] != i) ok = false;
  36. if (node.fi[5] != 0 || node.fi[6] != 0 || node.fi[4] != 8 || node.fi[7] != 4) ok = false;
  37. if (node.fi[8] != 7 || node.fi[9] != 6 || node.fi[10] != 5) ok = false;
  38. if (ok) {
  39. cout << node.si << '\n';
  40. return 0;
  41. }
  42.  
  43. if (vis[node.fi]) continue;
  44.  
  45. vis[node.fi] = true;
  46.  
  47. for (int i = 0; i <= 1; i++) {
  48. array<int, 11> a = node.fi;
  49. int tmp = a[d[5][i]];
  50.  
  51. for (int j = 0; j < 6; j++) {
  52. int k = d[j][i];
  53. swap(a[k], tmp);
  54. }
  55. if (!vis[a]) q.push({a, node.si + 1});
  56. }
  57. }
  58. }
  59.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty