# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88779 | tushar_2658 | Studentsko (COCI14_studentsko) | C++14 | 7 ms | 1100 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define file freopen("in.txt", "r", stdin);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define keepunique(v) (v).erase(unique(all(v)),v.end())
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);
const int maxn = 5005;
int n, k, cnt = 0;
ll arr[maxn];
map<ll, ll>mark;
vector<ll> vec, vec1;
int dp[maxn];
ll t[maxn];
int CeilIndex(std::vector<ll>& v, int l, int r, ll key)
{
while (r - l > 1) {
int m = l + (r - l) / 2;
if (v[m] >= key)
r = m;
else
l = m;
}
return r;
}
int LongestIncreasingSubsequenceLength(std::vector<ll>& v)
{
if (v.size() == 0)
return 0;
std::vector<ll> tail(v.size(), 0);
int length = 1;
tail[0] = v[0];
for (size_t i = 1; i < v.size(); i++) {
if (v[i] < tail[0])
tail[0] = v[i];
else if (v[i] >= tail[length - 1])
tail[length++] = v[i];
else
tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
}
return length;
}
int solve(){
for(int i=0; i<n; i++)vec1.pb(mark[arr[i]]);
int lon = 0;
return n - LongestIncreasingSubsequenceLength(vec1);
}
int main(){
//file
//fastread
scanf("%d%d", &n, &k);
for(int i=0; i<n; i++){
scanf("%lld", &arr[i]);
vec.pb(arr[i]);
}
//vec1 = vec;
sort(all(vec));
for(int i=0; i<n; i++){
if(i%k == 0)++cnt;
mark[vec[i]] = cnt;
}
printf("%d", solve());
}
Compilation message (stderr)
# | 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... |