제출 #763310

#제출 시각아이디문제언어결과실행 시간메모리
763310vjudge1Financial Report (JOI21_financial)C++17
48 / 100
805 ms197084 KiB
#include <bits/stdc++.h> using namespace std; const int NM = 7000, inf = 17; int N, D, A[NM+5], ans = 0; vector <int> v; int f[NM+5][NM+5]; deque <int> dq[NM+5]; void remove(int j, int i){ if (!dq[j].empty() && dq[j].front() == i) dq[j].pop_front(); } void add(int j, int i){ while (!dq[j].empty() && f[i][j] >= f[dq[j].back()][j]) dq[j].pop_back(); dq[j].push_back(i); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> D; for (int i = 1; i <= N; i++){ cin >> A[i]; v.push_back(A[i]); } sort(v.begin(), v.end()); for (int i = 1; i <= N; i++) A[i] = lower_bound(v.begin(), v.end(), A[i])-v.begin()+1; for (int i = 0; i <= N; i++) if (i != A[1]) f[1][i] = -inf; else f[1][i] = 1; for (int i = 0; i <= N; i++) dq[i].push_back(1); for (int i = 2; i <= N; i++){ for (int j = 0; j <= N; j++) if (j != A[i]) f[i][j] = -inf; else f[i][j] = 1; for (int j = 0; j <= N; j++){ if (i-D-1 >= 1) remove(j, i-D-1); if (j < A[i]) f[i][A[i]] = max(f[i][A[i]], f[dq[j].front()][j]+1); else f[i][j] = max(f[i][j], f[dq[j].front()][j]); } for (int j = 0; j <= N; j++) add(j, i); } for (int i = 0; i <= N; i++) ans = max(ans, f[N][i]); cout << ans; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...