이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 998244353;
#define fo(i,e) for(ll i = 0; i < e; i++)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 2e9
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int maxn = 5001;
void solve(){
int n,k;cin >> n >> k;
vector<int> srt, arr;
unordered_map<int,int> mp;
fo(i,n){
int tmep ;
cin >> tmep;
arr.pb(tmep);
}
srt = arr;
sort(srt.begin(), srt.end());
for(int i = 0 ; i<n ; i+=k) for(int j = 0; j<k; ++j) mp[srt[i+j]] = i;
fo(i,n){arr[i] = mp[arr[i]];}
int ans = 1;
int dp[n];
dp[0] =1;
for(int i = 1 ; i<n ; ++i){
dp[i] = 1;
for(int j = i-1; j>=0; --j){
if(arr[j]<=arr[i])
dp[i] = max(dp[i], dp[j]+1);
}
ans = max(ans, dp[i]);
}
cout << n-ans;
}
int main(){
fast_cin();
ll t=1;
//cin >> t;
for(int it=1;it<=t;it++) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |