Advertisement
PikMike

Untitled

Oct 2nd, 2016
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define mp make_pair
  5. #define sz(x) (int)(x).size()
  6. #define ll long long
  7. #define ld long double
  8. #define ft first
  9. #define sc second
  10. #define pii pair<int, int>
  11. #define pll pair<ll, ll>
  12. #define forn(i, t) for(int i = 0; i < (t); i++)
  13. #define fore(i, f, t) for(int i = (f); i < (t); i++)
  14. #define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
  15. #define all(x) (x).begin(), (x).end()
  16. #define ins insert
  17.  
  18. const int INF = 2147483647;
  19. const int MOD = 1000000007;
  20. const ll INF64 = 9223372036854775807;
  21. const ld EPS = 1e-7;
  22.  
  23. using namespace std;
  24.  
  25. map<int, int> m;
  26. vector<string> s(6);
  27.  
  28.  
  29. struct cube{
  30.     int x, y, z;
  31.     pair<char, char> a, b, c;
  32.     cube(int xa, int ya, int za, pair<char, char> aa, pair<char, char> ba, pair<char, char> ca, int mask){
  33.         x = xa;
  34.         y = ya;
  35.         z = za;
  36.         a = ((mask & 1) == 0 ? aa : mp(aa.sc, aa.ft));
  37.         b = ((mask & 2) == 0 ? ba : mp(ba.sc, ba.ft));
  38.         c = ((mask & 4) == 0 ? ca : mp(ca.sc, ca.ft));
  39.     }
  40. };
  41.  
  42.  
  43. vector<cube> ans;
  44. set<string> l;
  45.  
  46.  
  47. void add(int x, int y, int z, pair<char, char> a, pair<char, char> b, pair<char, char> c, int mask){
  48.     if (s[x][0] != ((mask & 1) == 0 ? a.ft : a.sc) ||
  49.         s[y][0] != ((mask & 2) == 0 ? b.ft : b.sc) ||
  50.         s[z][0] != ((mask & 4) == 0 ? c.ft : c.sc))
  51.         return;
  52.     string t;
  53.     t += b.ft;
  54.     t += b.sc;
  55.     t += c.ft;
  56.     t += c.sc;
  57.     sort(all(t));
  58.     if (t != s[x].substr(1, 4))
  59.         return;
  60.     t = "";
  61.     t += a.ft;
  62.     t += a.sc;
  63.     t += c.ft;
  64.     t += c.sc;
  65.     sort(all(t));
  66.     if (t != s[y].substr(1, 4))
  67.         return;
  68.     t = "";
  69.     t += a.ft;
  70.     t += a.sc;
  71.     t += b.ft;
  72.     t += b.sc;
  73.     sort(all(t));
  74.     if (t != s[z].substr(1, 4))
  75.         return;
  76.     ans.pb(cube(x, y, z, a, b, c, mask));
  77. }
  78.  
  79.  
  80. void turnCC(string &a){
  81.     string res = "";
  82.     // F Ba L  R T Bo
  83.     // F Ba Bo T L R
  84.     res += a[0];
  85.     res += a[1];
  86.     res += a[5];
  87.     res += a[4];
  88.     res += a[2];
  89.     res += a[3];
  90.     a = res;
  91. }
  92.  
  93.  
  94. void turnF(string &a){
  95.     string res = "";
  96.     // F  Ba L R T Bo
  97.     // Bo T  L R F Ba
  98.     res += a[5];
  99.     res += a[4];
  100.     res += a[2];
  101.     res += a[3];
  102.     res += a[0];
  103.     res += a[1];
  104.     a = res;
  105. }
  106.  
  107.  
  108. void turnR(string &a){
  109.     string res = "";
  110.     // F Ba L R  T Bo
  111.     // R L  F Ba T Bo
  112.     res += a[3];
  113.     res += a[2];
  114.     res += a[0];
  115.     res += a[1];
  116.     res += a[4];
  117.     res += a[5];
  118.     a = res;
  119. }
  120.  
  121.  
  122. string norm(cube &a){
  123.     string t = "";
  124.     t += a.a.ft;
  125.     t += a.a.sc;
  126.     t += a.b.ft;
  127.     t += a.b.sc;
  128.     t += a.c.ft;
  129.     t += a.c.sc;
  130.     return t;
  131. }
  132.  
  133.  
  134. bool check(string a){
  135.     forn(i, 4){
  136.         if (l.find(a) != l.end())
  137.             return 0;
  138.         turnCC(a);
  139.     }
  140.     turnF(a);
  141.     forn(i, 4){
  142.         if (l.find(a) != l.end())
  143.             return 0;
  144.         turnCC(a);
  145.     }
  146.     turnF(a);
  147.     forn(i, 4){
  148.         if (l.find(a) != l.end())
  149.             return 0;
  150.         turnCC(a);
  151.     }
  152.     turnF(a);
  153.     forn(i, 4){
  154.         if (l.find(a) != l.end())
  155.             return 0;
  156.         turnCC(a);
  157.     }
  158.     turnF(a);
  159.     turnR(a);
  160.     forn(i, 4){
  161.         if (l.find(a) != l.end())
  162.             return 0;
  163.         turnCC(a);
  164.     }
  165.     turnR(a);
  166.     turnR(a);
  167.     forn(i, 4){
  168.         if (l.find(a) != l.end())
  169.             return 0;
  170.         turnCC(a);
  171.     }
  172.     return 1;
  173. }
  174.  
  175.  
  176. int main(){
  177.     freopen("cube.in", "r", stdin);
  178.     freopen("cube.out", "w", stdout);
  179.     forn(i, 6){
  180.         cin >> s[i];
  181.         sort(++s[i].begin(), s[i].end());
  182.         // cout << s[i] << "\n";
  183.     }
  184.     forn(i, 6)
  185.         forn(j, 5)
  186.             m[s[i][j] - 'A']++;
  187.     vector<pair<char, char> > c, d;
  188.     forn(i, 6){
  189.         map<int, int> k = m;
  190.         forn(j, 5)
  191.             k[s[i][j] - 'A'] -= 5;
  192.         int cnt1 = 0, cnt2 = 0;
  193.         c.pb(mp(s[i][0], 'a'));
  194.         for (auto it = k.begin(); it != k.end(); it++){
  195.             // printf("[%d, %d] ", it->ft, it->sc);
  196.             if (it->sc == 0) cnt1++;
  197.             if (it->sc == 5){
  198.                 cnt2++;
  199.                 c[i].sc = ('A' + it->ft);
  200.             }
  201.         }
  202.         if (cnt1 + cnt2 != sz(m) || cnt2 != 1){
  203.             printf("Impossible\n");
  204.             return 0;
  205.         }
  206.         // printf("\n");
  207.     }
  208.     vector<char> used(6, 0);
  209.  
  210.     forn(i, 6){
  211.         forn(j, 6)
  212.             if (!used[j] && !used[i] && i != j && c[i].ft == c[j].sc && c[i].sc == c[j].ft){
  213.                 d.pb(c[i]);
  214.                 used[i] = 1;
  215.                 used[j] = 1;
  216.                 // cout << c[i].ft << " " << c[i].sc << "\n";
  217.                 break;
  218.             }
  219.     }
  220.     forn(mask, 8)
  221.         forn(i, 6)
  222.             forn(j, 6){
  223.                 if (i == j) continue;
  224.                 forn(k, 6){
  225.                     if (k == i || k == j) continue;
  226.                     add(i, j, k, d[0], d[1], d[2], mask);
  227.                 }
  228.             }
  229.     forn(mask, 8)
  230.         forn(i, 6)
  231.             forn(j, 6){
  232.                 if (i == j) continue;
  233.                 forn(k, 6){
  234.                     if (k == i || k == j) continue;
  235.                     add(i, j, k, d[0], d[2], d[1], mask);
  236.                 }
  237.             }
  238.     forn(mask, 8)
  239.         forn(i, 6)
  240.             forn(j, 6){
  241.                 if (i == j) continue;
  242.                 forn(k, 6){
  243.                     if (k == i || k == j) continue;
  244.                     add(i, j, k, d[1], d[0], d[2], mask);
  245.                 }
  246.             }
  247.     forn(mask, 8)
  248.         forn(i, 6)
  249.             forn(j, 6){
  250.                 if (i == j) continue;
  251.                 forn(k, 6){
  252.                     if (k == i || k == j) continue;
  253.                     add(i, j, k, d[1], d[2], d[0], mask);
  254.                 }
  255.             }
  256.     forn(mask, 8)
  257.         forn(i, 6)
  258.             forn(j, 6){
  259.                 if (i == j) continue;
  260.                 forn(k, 6){
  261.                     if (k == i || k == j) continue;
  262.                     add(i, j, k, d[2], d[0], d[1], mask);
  263.                 }
  264.             }
  265.     forn(mask, 8)
  266.         forn(i, 6)
  267.             forn(j, 6){
  268.                 if (i == j) continue;
  269.                 forn(k, 6){
  270.                     if (k == i || k == j) continue;
  271.                     add(i, j, k, d[2], d[1], d[0], mask);
  272.                 }
  273.             }
  274.     string z;
  275.     forn(i, sz(ans)){
  276.         z = norm(ans[i]);
  277.         if (check(z))
  278.             l.ins(z);
  279.     }
  280.     for (auto it = l.begin(); it != l.end(); it++){
  281.         // cout << *it << " ";
  282.         printf("%c%c%c%c%c%c\n", (*it)[0], (*it)[2], (*it)[4], (*it)[3], (*it)[5], (*it)[1]);
  283.     }
  284.     if (sz(l) == 0)
  285.         printf("Impossible\n");
  286.     // forn(i, sz(ans))
  287.     //     printf("%d %d %d [%c, %c] [%c, %c] [%c, %c]\n", ans[i].x, ans[i].y, ans[i].z, ans[i].a.ft, ans[i].a.sc, ans[i].b.ft, ans[i].b.sc, ans[i].c.ft, ans[i].c.sc);
  288.     return 0;
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement