3015.cpp (420B)
1 class Solution { 2 public: 3 vector<int> countOfPairs(int n, int x, int y) const { 4 vector<int> res(n); 5 6 x--, y--; 7 if (x > y) swap(x, y); 8 for (int i = 0; i < n - 1; i++) { 9 for (int j = i + 1; j < n; j++) { 10 const int dist = min(abs(i - j), abs(i - x) + abs(j - y) + 1); 11 res[dist - 1] += 2; 12 } 13 } 14 15 return res; 16 } 17 };