fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m, x, y;
  6. cin >> n >> m >> x >> y;
  7. int arr[n][m];
  8. int num = 0;
  9. for(int i = 0; i < n; ++i) {
  10. int dir, j;
  11. if(i % 2 == 0){
  12. j = 0;
  13. dir = 1;
  14. }
  15. else {
  16. j = m-1;
  17. dir = -1;
  18. }
  19. for(; j < m&&j >= 0; j+= dir) {
  20. arr[i][j] = num;
  21. ++num;
  22. }
  23. }
  24. cout << arr[x - 1][y - 1];
  25. return 0;
  26. }
Success #stdin #stdout 0s 4384KB
stdin
10 5 10 2
stdout
48