RT,下载数据本地测是对的。
#include <bits/stdc++.h>
using namespace std;
#define FILE(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout);
int n, ans, a[9][6], b[6];
int f(int x, int y){
if (x <= y){
return y - x;
} else {
return y + 10 - x;
}
}
bool g(int x){
int tmp = (bool)f(a[x][1], b[1]) + (bool)f(a[x][2], b[2]) + (bool)f(a[x][3], b[3]) + (bool)f(a[x][4], b[4]) + (bool)f(a[x][5], b[5]);
if (tmp == 1){
return true;
} else if (tmp == 2){
if (f(a[x][1], b[1]) && f(a[x][2], b[2])){
if (f(a[x][1], b[1]) == f(a[x][2], b[2])){
return true;
} else {
return false;
}
} else if (f(a[x][2], b[2]) && f(a[x][3], b[3])){
if (f(a[x][2], b[2]) == f(a[x][3], b[3])){
return true;
} else {
return false;
}
} else if (f(a[x][3], b[3]) && f(a[x][4], b[4])){
if (f(a[x][3], b[3]) == f(a[x][4], b[4])){
return true;
} else {
return false;
}
} else if (f(a[x][4], b[4]) && f(a[x][5], b[5])){
if (f(a[x][4], b[4]) == f(a[x][5], b[5])){
return true;
} else {
return false;
}
}
} else {
return false;
}
}
void dfs(int x){
if (x == 6){
for (int i = 1; i <= n; i++){
if (!g(i)){
return;
}
}
ans++;
return;
}
for (int i = 0; i <= 9; i++){
b[x] = i;
dfs(x + 1);
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4] >> a[i][5];
}
dfs(1);
cout << ans;
return 0;
}