fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define maxn 120
  4.  
  5. int a[maxn][maxn], m, n, t;
  6.  
  7. int check(int *i, int *j){
  8. int k, cnt_r, cnt_c;
  9. cnt_r = 0;
  10. for(k = *i + 1; k < m; k++){
  11. if(a[*i][*j] == a[k][*j]) cnt_r++;
  12. if(cnt_r >= t){
  13. *i = k;
  14. return 1;
  15. }
  16. }
  17. cnt_c = 0;
  18. for(k = *j + 1; k < n; k++){
  19. if(a[*i][*j] == a[*i][k]) cnt_c++;
  20. if(cnt_c >= t){
  21. *j = k;
  22. return 1;
  23. }
  24. }
  25. return 0;
  26. }
  27.  
  28. int lastSq(int r, int c){
  29. return (r == n - 1 && c == n);
  30. }
  31.  
  32. int main(){
  33. int res = 0, i, j, pos_r = 0, pos_c = 0;
  34. scanf("%d%d%d", &m, &n, &t);
  35. for(i = 0; i < m; i++)
  36. for(j = 0; j < n; j++)
  37. scanf("%d", &a[i][j]);
  38.  
  39. while(!lastSq(pos_r, pos_c)){
  40. if(a[pos_r][pos_c] == 0){
  41. if(pos_c < n - 1) pos_c++;
  42. else if(pos_r < n - 1){
  43. pos_c = 0;
  44. pos_r++;
  45. }
  46. }
  47. if(!check(&pos_r, &pos_c)){
  48. res++;
  49. if(pos_c < n - 1) pos_c++;
  50. else{
  51. pos_c = 0;
  52. pos_r++;
  53. }
  54. }
  55. }
  56.  
  57. printf("%d", res);
  58. }
Runtime error #stdin #stdout 0s 15288KB
stdin
Standard input is empty
stdout
Standard output is empty