fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int N,M,count,OK=0;
  5. int A[100][100],B[10000],C[100][100]={0};
  6. scanf("%d %d",&N,&M);
  7. for(int i=0;i<N;i++){
  8. for(int j=0;j<N;j++){
  9. scanf("%d",&A[i][j]);
  10. }
  11. }
  12. for(int i=0;i<M;i++){
  13. scanf("%d",&B[i]);
  14. }
  15. for(int t=0;t<M;t++){
  16. for(int i=0;i<N;i++){
  17. for(int j=0;j<N;j++){
  18. if(B[t] == A[i][j]){
  19. C[i][j]=1;
  20. }
  21. }
  22. }
  23. }
  24. for(int i=0;i<N;i++){
  25. count=0;
  26. for(int j=0;j<N;j++){
  27. if(C[i][j]==1){
  28. count++;
  29. }
  30. }
  31. if(count==N){
  32. OK=1;
  33. }
  34. }
  35. for(int j=0;j<N;j++){
  36. count=0;
  37. for(int i=0;i<N;i++){
  38. if(C[i][j]==1){
  39. count++;
  40. }
  41. }
  42. if(count==N){
  43. OK=1;
  44. }
  45. }
  46. for(int i=0;i<N;i++){
  47. count=0;
  48. if(C[i][i]==1){
  49. count++;
  50. }
  51. if(count==N){
  52. OK=1;
  53. }
  54. count=0;
  55. if(C[N-1-i][i]==1){
  56. count++;
  57. }
  58. if(count==N){
  59. OK=1;
  60. }
  61. }
  62. if(OK==1){
  63. printf("Yes");
  64. }
  65. else{
  66. printf("No");
  67. }
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 5324KB
stdin
3 7
1 2 3
4 5 6
7 8 9
1 2 5 8 3 9 7
stdout
Yes