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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include<bits/stdc++.h> #include <ostream>
using namespace std; typedef long long ll; #define endl '\n' typedef pair<int, int> PII; #define debug() cout.flush() #define for0(i, a) for (ll i = 0; i < a; ++i) #define REP(i, a, b) for (int i = a; i < b; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define REPC(i, a, b, c) for (ll i = a; i < b && i < c; ++i) #define RREP(i, a, b) for (int i = a; i >= b; --i) const ll MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const int MAXN = 3e7 + 5e5; const int N = 1e5; const int S = 300;
inline void init() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int a[MAXN], b[MAXN * 2];
inline void solve() { int n; cin >> n; REP (i, 0, n) { cin >> a[i]; } int ans = 1; REP (i, -S, S + 1) { REP (j, 0, n) { ++b[a[j] - i * j + MAXN]; } REP (j, 0, n) { ans = max(ans, b[a[j] - i * j + MAXN]); b[a[j] - i * j + MAXN] = 0; } } REP (i, 0, n) { REP (j, i + 1, min(n, i + N / S + 1)) { if (!((a[j] - a[i]) % (j - i))) { int sub = (a[j] - a[i]) / (j - i); if (sub >= -S && sub <= S) continue; ans = max(ans, (++b[sub + MAXN]) + 1); } } REP (j, i + 1, min(n, i + N / S + 1)) { if (!((a[j] - a[i]) % (j - i))) { int sub = (a[j] - a[i]) / (j - i); b[sub + MAXN] = 0; } } } cout << n - ans << endl; }
signed main() { init(); solve(); return 0; }
|