记录编号 |
583790 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[CSP 2023S]密码锁 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.000 s |
提交时间 |
2023-10-23 16:53:33 |
内存使用 |
0.00 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n,ans;
int a[20][20],s[20],u[20];
int push(int x,int y){
return (x > y?9-x+y+1:y-x);
}
bool check(){
for(int i = 1;i <= n;i++){
memset(u,0,sizeof(u));
int same = 0,f = 0;
for(int j = 1;j <= 5;j++){
if(s[j] == a[i][j]){
same++;
if(f)f = 2;
}
else{
if(f == 2)return 0;
f = 1;
u[push(s[j],a[i][j])]++;
}
}
f = 0;
if(same == 5 || same < 3)return 0;
for(int j = 0;j <= 9;j++){
if(u[j] == 2){
if(f)return 0;
f = 1;
}
else if(u[j] == 1){
if(f)return 0;
f = 1;
}
else if(u[j] != 0)return 0;
}
}
return 1;
}
void sou(int x){
if(x == 6){
if(check()){
ans++;
}
return;
}
for(int i = 0;i <= 9;i++){
s[x] = i;
sou(x+1);
s[x] = 0;
}
}
int main(){
freopen("lock.in","r",stdin);
freopen("lock.out","w",stdout);
scanf("%d",&n);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= 5;j++)scanf("%d",&a[i][j]);
sou(1);
printf("%d\n",ans);
return 0;
}