fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int m, n;
  6. cin >> m >> n;
  7. double M[m][n];
  8. bool monotone[m];
  9.  
  10. for (int i = 0; i < m; i++)
  11. for (int j = 0; j < n; j++)
  12. cin >> M[i][j];
  13.  
  14. for (int i = 0; i < m; i++) {
  15. bool check = true, diff;
  16. if (M[i][0] != M[i][1]) {
  17. diff = (M[i][1] > M[i][0]);
  18. for (int j = 2; j < n; j++)
  19. if ((M[i][j] == M[i][j-1]) || ((M[i][j] > M[i][j-1]) != diff)) {
  20. check = false;
  21. break;
  22. }
  23. }
  24. else
  25. check = false;
  26. monotone[i] = check;
  27. }
  28.  
  29. for (int i = 0; i < m; i++)
  30. cout << monotone[i] << endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3416KB
stdin
5
5
1  2.5  3  -5  2
-7  -4.5  -2.8  0 1
8 3 0 -2.9 -4.62
8  3 3  -2.9  -4.62
1 2 3 3 4
stdout
0
1
1
0
0