Submission #365505

# Submission time Handle Problem Language Result Execution time Memory
365505 2021-02-11T18:41:36 Z alrad Studentsko (COCI14_studentsko) C++17
100 / 100
46 ms 620 KB
#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using ull = unsigned long long;

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

template <class T> inline T gcd(T a , T b) { return !a ? b : gcd(b % a , a); }
template <class T> inline T lcm(T a , T b) {return (a * b) / gcd(a , b) ; }

mt19937 rnd(time(0));

#define all(x) x.begin(), x.end()
#define debug(x) { cerr << #x << " = " << x << endl; }ы

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i] = {x, i};
  }
  sort(all(a)), reverse(all(a));
  vector<int> nums(n, -1);
  for (int i = 0; i < n; i++) {
    nums[a[i].second] = (i / k + 1);
  }
  int ans = 0;
  reverse(all(nums));
  vector<int> dp(n, 0);
  for (int i = 0; i < n; i++) {
    int par = -1;
    for (int j = 0; j < i; j++) {
      if (nums[j] <= nums[i] && (par == -1 || dp[j] > dp[par])) {
        par = j;
      }
    }
    if (par != -1) {
      dp[i] += dp[par];
    }
    dp[i] += 1;
    ans = max(ans, dp[i]);
  }
  cout << n - ans << '\n';
  return;
}

signed main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0) , cout.tie(0);
  int t = 1;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
# 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 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 492 KB Output is correct
2 Correct 34 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 492 KB Output is correct
2 Correct 46 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 492 KB Output is correct
2 Correct 29 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 492 KB Output is correct
2 Correct 41 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 492 KB Output is correct
2 Correct 42 ms 524 KB Output is correct