Submission #40630

# Submission time Handle Problem Language Result Execution time Memory
40630 2018-02-06T00:49:07 Z Hassoony Studentsko (COCI14_studentsko) C++14
100 / 100
9 ms 1212 KB
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef unsigned long long ll;
typedef double D;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=5009;
int n,k,a[MX],dp[MX];
int bn(int l,int r,int x){
    int ans=0;
    while(l<=r){
        int mid=(l+r)/2;
        if(dp[mid]>x)r=mid-1;
        else l=mid+1;
    }
    return l;
}
int DP(){
    int ans=1;
    dp[0]=a[0];
    for(int i=1;i<n;i++){
        if(a[i]<dp[0])dp[0]=a[i];
        else if(a[i]>=dp[ans-1])dp[ans++]=a[i];
        else dp[bn(0,ans,a[i])]=a[i];
    }
    return ans;
}
map<int,int>hashy;
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        hashy[a[i]]=1;
    }
    int tt=1,j=1;
    for(auto pp:hashy){
        hashy[pp.first]=tt;
        if(j%k==0)++tt;
        j++;
    }
    for(int i=0;i<n;i++)a[i]=hashy[a[i]];
    cout<<n-DP()<<endl;
}

Compilation message

studentsko.cpp: In function 'int bn(int, int, int)':
studentsko.cpp:11:9: warning: unused variable 'ans' [-Wunused-variable]
     int ans=0;
         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 532 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 532 KB Output is correct
2 Correct 1 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 804 KB Output is correct
2 Correct 9 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 860 KB Output is correct
2 Correct 6 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 916 KB Output is correct
2 Correct 6 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 972 KB Output is correct
2 Correct 7 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 984 KB Output is correct
2 Correct 7 ms 1212 KB Output is correct