제출 #1017153

#제출 시각아이디문제언어결과실행 시간메모리
1017153NguyenPhucThangRabbit Carrot (LMIO19_triusis)C++14
100 / 100
92 ms13516 KiB
#include <bits/stdc++.h> #define forr(i, a, b) for (int i = a; i <= b; i++) #define ford(i, a, b) for (int i = a; i >= b; i--) #define fi first #define se second #define pb push_back #define all(v) v.begin(), v.end() #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vii vector<pii> #define file "test" using namespace std; const int base = 31; const ll mod = 1e9 + 7; const ll oo = 1e18; const int N = 4e5 + 5; const int V = 4e5; int dp[N], st[4*N]; ll h[N], t[N]; vector<ll> nen; void update(int id, int l, int r, int i, int v){ if (i < l || r < i) return; if (l == r){ st[id] = max(st[id], v); return; } int mid = (l + r) >> 1; update(2 * id, l, mid, i, v), update(2 * id + 1, mid + 1, r, i, v); st[id] = max(st[2 * id], st[2 * id + 1]); } int get(int id, int l, int r, int u, int v){ if (v < l || r < u) return 0; if (u <= l && r <= v) return st[id]; int mid = (l + r) >> 1; return max(get(2 * id, l, mid, u, v), get(2 * id + 1, mid + 1, r, u, v)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, M; cin >> n >> M; n += 1; h[1] = 0; t[1] = h[1] - M; nen.pb(t[1]); forr(i, 2, n){ cin >> h[i]; t[i] = h[i] - M*i; nen.pb(t[i]); } sort(all(nen)); nen.resize(unique(all(nen)) - nen.begin()); forr(i,1,n) t[i] = lower_bound(all(nen), t[i]) - nen.begin() + 1; dp[1] = 1; update(1, 1, V, t[1], dp[1]); forr(i, 2, n){ int f = get(1, 1, V, t[i], V); if (f) { dp[i] = f + 1; update(1, 1, V, t[i], dp[i]); } } int res = 0; forr(i, 1, n) dp[i] -= 1; forr(i, 2, n) res = max(res, dp[i]); cout << (n - 1) - res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...