-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj1116.cpp
More file actions
109 lines (98 loc) · 2.27 KB
/
aoj1116.cpp
File metadata and controls
109 lines (98 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int cnt;
char tonum(char word) {
if(word == 'R') return '1';
if(word == 'G') return '2';
if(word == 'B') return '3';
if(word == 'W') return '4';
if(word == 'r') return '5';
if(word == 'g') return '6';
if(word == 'b') return '7';
if(word == 'w') return '8';
return '0';
}
void calc(int num, string rest, string ing) {
string bkup_r = rest;
string bkup_i = ing;
if(num==9) {
cnt++; return;
}
if(num == 0) {
for(int i=0; i<9; i++) {
for(int j=0; j<4; j++) {
ing.push_back(rest[j%4 + i*4]);
ing.push_back(rest[(j+1)%4 + i*4]);
ing.push_back(rest[(j+2)%4 + i*4]);
ing.push_back(rest[(j+3)%4 + i*4]);
calc(1, rest.erase(i*4, 4), ing);
rest = bkup_r;
ing = "";
}
}
}
else if(num<3) {
for(int i=0; i<rest.size(); i++) {
if(abs((int)ing[2+(num-1)*4] - (int)rest[i]) == 4) {
ing.push_back(rest[i%4 + i/4*4]);
ing.push_back(rest[(i+1)%4 + i/4*4]);
ing.push_back(rest[(i+2)%4 + i/4*4]);
ing.push_back(rest[(i+3)%4 + i/4*4]);
calc(num+1, rest.erase(i/4*4, 4), ing);
rest = bkup_r;
ing = bkup_i;
}
}
}
else if(num%3 == 0) {
for(int i=0; i<rest.size(); i++) {
if(abs((int)ing[3+(num-3)*4] - (int)rest[i]) == 4) {
ing.push_back(rest[(i+3)%4 + i/4*4]);
ing.push_back(rest[i%4 + i/4*4]);
ing.push_back(rest[(i+1)%4 + i/4*4]);
ing.push_back(rest[(i+2)%4 + i/4*4]);
calc(num+1, rest.erase(i/4*4, 4), ing);
rest = bkup_r;
ing = bkup_i;
}
}
}
else {
for(int i=0; i<rest.size(); i++) {
if(abs((int)ing[2+(num-1)*4] - (int)rest[i]) == 4 &&
abs((int)ing[3+(num-3)*4] - (int)rest[(i+1)%4 + i/4*4]) == 4) {
ing.push_back(rest[i%4 + i/4*4]);
ing.push_back(rest[(i+1)%4 + i/4*4]);
ing.push_back(rest[(i+2)%4 + i/4*4]);
ing.push_back(rest[(i+3)%4 + i/4*4]);
calc(num+1, rest.erase(i/4*4, 4), ing);
rest = bkup_r;
ing = bkup_i;
}
}
}
}
int main() {
int n;
char input;
string pieces;
cin >> n;
for(int t=0; t<n; t++) {
pieces = "";
for(int i=0; i<36; i++) {
cin >> input;
pieces.push_back(tonum(input));
}
cnt = 0;
calc(0, pieces, "");
cout << cnt << endl;
}
return 0;
}