Submission #960056

# Submission time Handle Problem Language Result Execution time Memory
960056 2024-04-09T15:07:30 Z AeonARY Studentsko (COCI14_studentsko) C++17
100 / 100
36 ms 2904 KB
#include <bits/stdc++.h>
using namespace std;

#define Task "DATA"
#define ll long long
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)

const int N = 1e6 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int a[N], dp[N];
map<int, int> g;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(Task".INP", "r")) {
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }

    int n, k;
    cin >> n >> k;

    vector<int> v;
    FOR(i, 1, n) cin >> a[i], v.push_back(a[i]);
    sort(v.begin(), v.end());

    FOR(i, 0, n - 1) g[v[i]] = i / k;
    FOR(i, 1, n) a[i] = g[a[i]];

    int ans = 0;
    FOR(i, 1, n) {
        dp[i] = 1;
        FOR(j, 1, i - 1) if (a[j] <= a[i])
            dp[i] = max(dp[i], dp[j] + 1);
        ans = max(ans, dp[i]);
    }
    cout << n - ans;

    return 0;
}

Compilation message

studentsko.cpp: In function 'int main()':
studentsko.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(Task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
studentsko.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(Task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2648 KB Output is correct
2 Correct 29 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2648 KB Output is correct
2 Correct 34 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2904 KB Output is correct
2 Correct 14 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2652 KB Output is correct
2 Correct 32 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2828 KB Output is correct
2 Correct 34 ms 2832 KB Output is correct