Advertisement
fit_max

ZigZag (50%)

Dec 7th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6.  
  7. static long[][] matrix;
  8.  
  9. public static void main(String[] args) throws IOException {
  10. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  11. String[] arr = in.readLine().split(" ");
  12. int N = Integer.parseInt(arr[0]);
  13. int M = Integer.parseInt(arr[1]);
  14. matrix = new long[N][M];
  15. long result = 0;
  16. for (int i = 0; i < matrix.length; i++) {
  17. for (int j = 0; j < matrix[i].length; j++) {
  18. if ((i + j) % 2 == 0) {
  19. if (i == 0 || j == 0 || i == matrix.length - 1 || j == matrix[i].length - 1) {
  20. result += (3 * (i + j) + 1);
  21. } else {
  22. result += ((3 * (i + j) + 1) * 2);
  23. }
  24. }
  25. }
  26. }
  27. System.out.println(result);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement