记录编号 583790 评测结果 AAAAAAAAAA
题目名称 [CSP 2023S]密码锁 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2023-10-23 16:53:33 内存使用 0.00 MiB
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,ans;
  4. int a[20][20],s[20],u[20];
  5. int push(int x,int y){
  6. return (x > y?9-x+y+1:y-x);
  7. }
  8. bool check(){
  9. for(int i = 1;i <= n;i++){
  10. memset(u,0,sizeof(u));
  11. int same = 0,f = 0;
  12. for(int j = 1;j <= 5;j++){
  13. if(s[j] == a[i][j]){
  14. same++;
  15. if(f)f = 2;
  16. }
  17. else{
  18. if(f == 2)return 0;
  19. f = 1;
  20. u[push(s[j],a[i][j])]++;
  21. }
  22. }
  23. f = 0;
  24. if(same == 5 || same < 3)return 0;
  25. for(int j = 0;j <= 9;j++){
  26. if(u[j] == 2){
  27. if(f)return 0;
  28. f = 1;
  29. }
  30. else if(u[j] == 1){
  31. if(f)return 0;
  32. f = 1;
  33. }
  34. else if(u[j] != 0)return 0;
  35. }
  36. }
  37. return 1;
  38. }
  39. void sou(int x){
  40. if(x == 6){
  41. if(check()){
  42. ans++;
  43. }
  44. return;
  45. }
  46. for(int i = 0;i <= 9;i++){
  47. s[x] = i;
  48. sou(x+1);
  49. s[x] = 0;
  50. }
  51. }
  52. int main(){
  53. freopen("lock.in","r",stdin);
  54. freopen("lock.out","w",stdout);
  55. scanf("%d",&n);
  56. for(int i = 1;i <= n;i++)
  57. for(int j = 1;j <= 5;j++)scanf("%d",&a[i][j]);
  58. sou(1);
  59. printf("%d\n",ans);
  60. return 0;
  61. }