# Untitled

a guest
Jul 16th, 2019
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <bits/stdc++.h>
2. using namespace std;
3.
4. typedef long long ll;
5. #define FOR(i,a,b) for(ll i=(a);i<(b);i++)
6. #define FORd(i,a,b) for(ll i=(a)-1;i>=(b);i--)
7.
8. string a[7][7],f[7][8];
9. ll d[7][8], C[4] = {-1,+1,0,0};
10.
11. void res() {
12.     cout << 1;
13. }
14. void Try(ll x, ll y) {
15.     FOR(i,0,4)
16.         if (!(((x==0) && (y==0) && ((i==0) || (i==3))) || ((x==0) && (y==7) && ((i==0) || (i==2))) || ((x==6) && (y==0) && ((i==1) || (i==3))) || ((x==6) && (y==7) && ((i==1) || (i==2)))) || (f[x][y]=="")) {
17.             f[x][y] = a[d[x][y]][d[x + C[i]][y + C[3 - i]]];
18.             f[x + C[i]][y + C[i]] = f[x][y];
19.             if (x == 6 && y == 7) res();
20.             else if (y == 7) Try(x + 1, 0);
21.             else Try(x, y + 1);
22.             f[x][y] = "";
23.             f[x + C[i]][y + C[i]] = "";
24.         }
25. }
26.
27. int main() {
28.     freopen("test.inp", "r", stdin);
29.     freopen("test.out", "w", stdout);
30.     ll t = 6, n = 28;
31.     FORd(i,7,0) {
32.         FORd(j,7,t) {
33.             stringstream ss;
34.             ss << n--;
35.             ss >> a[i][j];
36.             if (a[i][j].size() == 1) a[i][j] = "0" + a[i][j];
37.             a[j][i] = a[i][j];
38.         }
39.         t--;
40.     }
41.     FOR(i,0,7)
42.         FOR(j,0,8) cin >> d[i][j];
43.     FOR(i,0,7)
44.         FOR(j,0,8) f[i][j] = "";
45.     Try(0, 0);
46. }
RAW Paste Data