Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz(x) (int)(x).size()
- #define ll long long
- #define ld long double
- #define ft first
- #define sc second
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define forn(i, t) for(int i = 0; i < (t); i++)
- #define fore(i, f, t) for(int i = (f); i < (t); i++)
- #define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- const int INF = 2147483647;
- const int MOD = 1000000007;
- const ll INF64 = 9223372036854775807;
- const ld EPS = 1e-7;
- using namespace std;
- map<int, int> m;
- vector<string> s(6);
- struct cube{
- int x, y, z;
- pair<char, char> a, b, c;
- cube(int xa, int ya, int za, pair<char, char> aa, pair<char, char> ba, pair<char, char> ca, int mask){
- x = xa;
- y = ya;
- z = za;
- a = ((mask & 1) == 0 ? aa : mp(aa.sc, aa.ft));
- b = ((mask & 2) == 0 ? ba : mp(ba.sc, ba.ft));
- c = ((mask & 4) == 0 ? ca : mp(ca.sc, ca.ft));
- }
- };
- vector<cube> ans;
- set<string> l;
- void add(int x, int y, int z, pair<char, char> a, pair<char, char> b, pair<char, char> c, int mask){
- if (s[x][0] != ((mask & 1) == 0 ? a.ft : a.sc) ||
- s[y][0] != ((mask & 2) == 0 ? b.ft : b.sc) ||
- s[z][0] != ((mask & 4) == 0 ? c.ft : c.sc))
- return;
- string t;
- t += b.ft;
- t += b.sc;
- t += c.ft;
- t += c.sc;
- sort(all(t));
- if (t != s[x].substr(1, 4))
- return;
- t = "";
- t += a.ft;
- t += a.sc;
- t += c.ft;
- t += c.sc;
- sort(all(t));
- if (t != s[y].substr(1, 4))
- return;
- t = "";
- t += a.ft;
- t += a.sc;
- t += b.ft;
- t += b.sc;
- sort(all(t));
- if (t != s[z].substr(1, 4))
- return;
- ans.pb(cube(x, y, z, a, b, c, mask));
- }
- void turnCC(string &a){
- string res = "";
- // F Ba L R T Bo
- // F Ba Bo T L R
- res += a[0];
- res += a[1];
- res += a[5];
- res += a[4];
- res += a[2];
- res += a[3];
- a = res;
- }
- void turnF(string &a){
- string res = "";
- // F Ba L R T Bo
- // Bo T L R F Ba
- res += a[5];
- res += a[4];
- res += a[2];
- res += a[3];
- res += a[0];
- res += a[1];
- a = res;
- }
- void turnR(string &a){
- string res = "";
- // F Ba L R T Bo
- // R L F Ba T Bo
- res += a[3];
- res += a[2];
- res += a[0];
- res += a[1];
- res += a[4];
- res += a[5];
- a = res;
- }
- string norm(cube &a){
- string t = "";
- t += a.a.ft;
- t += a.a.sc;
- t += a.b.ft;
- t += a.b.sc;
- t += a.c.ft;
- t += a.c.sc;
- return t;
- }
- bool check(string a){
- forn(i, 4){
- if (l.find(a) != l.end())
- return 0;
- turnCC(a);
- }
- turnF(a);
- forn(i, 4){
- if (l.find(a) != l.end())
- return 0;
- turnCC(a);
- }
- turnF(a);
- forn(i, 4){
- if (l.find(a) != l.end())
- return 0;
- turnCC(a);
- }
- turnF(a);
- forn(i, 4){
- if (l.find(a) != l.end())
- return 0;
- turnCC(a);
- }
- turnF(a);
- turnR(a);
- forn(i, 4){
- if (l.find(a) != l.end())
- return 0;
- turnCC(a);
- }
- turnR(a);
- turnR(a);
- forn(i, 4){
- if (l.find(a) != l.end())
- return 0;
- turnCC(a);
- }
- return 1;
- }
- int main(){
- freopen("cube.in", "r", stdin);
- freopen("cube.out", "w", stdout);
- forn(i, 6){
- cin >> s[i];
- sort(++s[i].begin(), s[i].end());
- // cout << s[i] << "\n";
- }
- forn(i, 6)
- forn(j, 5)
- m[s[i][j] - 'A']++;
- vector<pair<char, char> > c, d;
- forn(i, 6){
- map<int, int> k = m;
- forn(j, 5)
- k[s[i][j] - 'A'] -= 5;
- int cnt1 = 0, cnt2 = 0;
- c.pb(mp(s[i][0], 'a'));
- for (auto it = k.begin(); it != k.end(); it++){
- // printf("[%d, %d] ", it->ft, it->sc);
- if (it->sc == 0) cnt1++;
- if (it->sc == 5){
- cnt2++;
- c[i].sc = ('A' + it->ft);
- }
- }
- if (cnt1 + cnt2 != sz(m) || cnt2 != 1){
- printf("Impossible\n");
- return 0;
- }
- // printf("\n");
- }
- vector<char> used(6, 0);
- forn(i, 6){
- forn(j, 6)
- if (!used[j] && !used[i] && i != j && c[i].ft == c[j].sc && c[i].sc == c[j].ft){
- d.pb(c[i]);
- used[i] = 1;
- used[j] = 1;
- // cout << c[i].ft << " " << c[i].sc << "\n";
- break;
- }
- }
- forn(mask, 8)
- forn(i, 6)
- forn(j, 6){
- if (i == j) continue;
- forn(k, 6){
- if (k == i || k == j) continue;
- add(i, j, k, d[0], d[1], d[2], mask);
- }
- }
- forn(mask, 8)
- forn(i, 6)
- forn(j, 6){
- if (i == j) continue;
- forn(k, 6){
- if (k == i || k == j) continue;
- add(i, j, k, d[0], d[2], d[1], mask);
- }
- }
- forn(mask, 8)
- forn(i, 6)
- forn(j, 6){
- if (i == j) continue;
- forn(k, 6){
- if (k == i || k == j) continue;
- add(i, j, k, d[1], d[0], d[2], mask);
- }
- }
- forn(mask, 8)
- forn(i, 6)
- forn(j, 6){
- if (i == j) continue;
- forn(k, 6){
- if (k == i || k == j) continue;
- add(i, j, k, d[1], d[2], d[0], mask);
- }
- }
- forn(mask, 8)
- forn(i, 6)
- forn(j, 6){
- if (i == j) continue;
- forn(k, 6){
- if (k == i || k == j) continue;
- add(i, j, k, d[2], d[0], d[1], mask);
- }
- }
- forn(mask, 8)
- forn(i, 6)
- forn(j, 6){
- if (i == j) continue;
- forn(k, 6){
- if (k == i || k == j) continue;
- add(i, j, k, d[2], d[1], d[0], mask);
- }
- }
- string z;
- forn(i, sz(ans)){
- z = norm(ans[i]);
- if (check(z))
- l.ins(z);
- }
- for (auto it = l.begin(); it != l.end(); it++){
- // cout << *it << " ";
- printf("%c%c%c%c%c%c\n", (*it)[0], (*it)[2], (*it)[4], (*it)[3], (*it)[5], (*it)[1]);
- }
- if (sz(l) == 0)
- printf("Impossible\n");
- // forn(i, sz(ans))
- // 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);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement