제출 #937381

#제출 시각아이디문제언어결과실행 시간메모리
937381stefanneaguMoney (IZhO17_money)C++17
9 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 1; int v[nmax], dp[nmax]; int main() { int n; cin >> n; vector<vector<int>> srt(n + 1); srt[0].push_back(0); for(int i = 1; i <= n; i ++) { cin >> v[i]; srt[i] = srt[i - 1]; srt[i].push_back(v[i]); sort(srt[i].begin(), srt[i].end()); dp[i] = 1e9; } dp[1] = 1; for(int i = 2; i <= n; i ++) { if(v[i] < v[i - 1]) { break; } dp[i] = 1; } for(int i = 2; i <= n; i ++) { int j = i; int x = upper_bound(srt[i - 1].begin(), srt[i - 1].end(), v[i]) - srt[i - 1].begin(); while(true) { dp[j] = min(dp[j], dp[i - 1] + 1); j ++; if(j == n + 1 || v[j] < v[j - 1] || v[j] > srt[i - 1][x]) { break; } } // cout << i << ": " << dp[i] << '\n'; } cout << dp[n]; 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...