Submission #353761

# Submission time Handle Problem Language Result Execution time Memory
353761 2021-01-21T10:13:18 Z SavicS Studentsko (COCI14_studentsko) C++14
100 / 100
46 ms 620 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll,int> pii;
const int maxn = 5005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, k;
ll niz[maxn];

pii pom[maxn];

int dp[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> k;
    ff(i,1,n){
        cin >> niz[i];
        pom[i].fi = niz[i];
        pom[i].se = i;
    }
    sort(pom + 1, pom + n + 1);
    ff(i,0,n / k - 1){
        ff(j,1,k)pom[j + i * k].fi = i + 1;
    }
    ff(i,1,n)niz[pom[i].se] = pom[i].fi;
    ff(i,1,n){
        fb(j,i - 1, 0){
            if(niz[i] >= niz[j])dp[i] = max(dp[i], dp[j] + 1);
        }
    }
    int rez = 0;
    ff(i,1,n)rez = max(rez, dp[i]);
    cout << n - rez << endl;
    return 0;
}
/**



// probati bojenje sahovski ili slicno

**/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 620 KB Output is correct
2 Correct 38 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 492 KB Output is correct
2 Correct 45 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 584 KB Output is correct
2 Correct 35 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 492 KB Output is correct
2 Correct 45 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 492 KB Output is correct
2 Correct 46 ms 492 KB Output is correct