fork(7) download
  1. #include <iostream>
  2. #define Unknown 1001
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, m,uf = 0,maxi;
  7. //input
  8. cin >> n >> m;
  9. int ** x = new int * [n];
  10. for (int i = 0; i < n; i++)
  11. x[i] = new int[m];
  12. for (int i = 0; i < n; i++)
  13. for (int j = 0; j < m; j++)
  14. cin >> x[i][j];
  15. //workspace
  16. int max[m];
  17. for (int i = 0; i < m; i++){
  18. max[i] = Unknown;
  19. }
  20. for (int i = 0; i < n; i++) {
  21. int min = x[i][0];
  22. for (int j = 1; j < m; j++) {
  23. if ( min > x[i][j] ) {
  24. min = x[i][j];
  25. }
  26. }
  27. for (int j = 0; j < m; j++) {
  28. if (x[i][j] == min) {
  29. if (max[j] != Unknown){
  30. maxi = max[j];
  31. }
  32. else {
  33. maxi = x[i][j];
  34. for (int l = 0; l < n; l++) {
  35. if (maxi < x[l][j]){
  36. maxi = x[l][j];
  37. }
  38. }
  39. max[j] = maxi;
  40. }
  41. if ( maxi == min) {
  42. uf++;
  43. }
  44. }
  45. }
  46. }
  47. //output
  48. cout << uf;
  49. return 0;
  50. }
Success #stdin #stdout 0s 4268KB
stdin
2 2
3 2
1 1
stdout
1