fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. int m = in.nextInt(), n = in.nextInt();
  11. double[][] M = new double[m][n];
  12. boolean[] monotone = new boolean[m];
  13.  
  14. for (int i = 0; i < m; i++)
  15. for (int j = 0; j < n; j++)
  16. M[i][j] = in.nextDouble();
  17.  
  18. for (int i = 0; i < m; i++) {
  19. boolean check = true, diff;
  20. if (M[i][0] != M[i][1]) {
  21. diff = (M[i][1] > M[i][0]);
  22. for (int j = 2; j < n; j++)
  23. if ((M[i][j] == M[i][j-1]) || ((M[i][j] > M[i][j-1]) != diff)) {
  24. check = false;
  25. break;
  26. }
  27. }
  28. else
  29. check = false;
  30. monotone[i] = check;
  31. }
  32.  
  33. for (int i = 0; i < m; i++)
  34. System.out.println(monotone[i]);
  35. }
  36. }
Success #stdin #stdout 0.16s 321280KB
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
false
true
true
false
false