Submission #40630

#TimeUsernameProblemLanguageResultExecution timeMemory
40630HassoonyStudentsko (COCI14_studentsko)C++14
100 / 100
9 ms1212 KiB
#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 (stderr)

studentsko.cpp: In function 'int bn(int, int, int)':
studentsko.cpp:11:9: warning: unused variable 'ans' [-Wunused-variable]
     int ans=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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...