blob: 9538e949d977e9470b64200f6dc6879ba7bdd390 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <cmath>
#include <iostream>
int w, m, n;
int row(int x) { return (x - 1) / w; }
int col(int x, int r) {
int result = (x - 1) % w;
if (r % 2) {
result = w - 1 - result;
}
return result;
}
int main() {
std::cin >> w >> m >> n;
int m_r = row(m);
int m_c = col(m, m_r);
int n_r = row(n);
int n_c = col(n, n_r);
std::cout << std::abs(m_r - n_r) + std::abs(m_c - n_c);
return 0;
}
|