boolisArti(vector<int>::iterator begin, vector<int>::iterator end){ auto itr = begin + 1; int diff = *itr - *begin; for (; itr < end; itr++) { if (*itr - *(itr - 1) != diff) { returnfalse; } } returntrue; }
intartiSeq(vector<int> &A){ int ans = 0; for (int i = 0; i + 3 <= A.size(); i++) { for (int len = 3; i + len <= A.size(); len++) { if (isArti(A.begin() + i, A.begin() + i + len)) { ans += 1; } } } return ans; }
intmoveNumber(vector<int> &A){ int ans = 0; sort(A.begin(), A.end()); vector<int> order(A.size()); for (int i = 0; i < order.size(); i++) { order[i] = i + 1; } for (int i = 0; i < A.size(); i++) { ans += abs(order[i] - A[i]); } if (ans > 1000000000) { return-1; } return ans; }