Submission #919125

# Submission time Handle Problem Language Result Execution time Memory
919125 2024-01-31T10:47:54 Z TIN Studentsko (COCI14_studentsko) C++17
100 / 100
4 ms 828 KB
#include <bits/stdc++.h>

using namespace std;

#define FNAME "test"

const int N = 5005;

int n,k;
int v[N], x[N];
int group = 1;
map<int,int> mp;
int g[N];
int dp[N];

void Task() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(9);
	if (fopen(FNAME".inp","r")) {
		freopen(FNAME".inp","r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

void Solve() {
	//Your Code
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		x[i] = v[i];
	}
	sort(x + 1, x + n + 1);
	for (int i = 1; i <= n; i++) {
		mp[x[i]] = group;
		if (i % k == 0) group++;
	}
	for (int i = 1; i <= n; i++) g[i] = mp[v[i]];
	for (int i = 0; i <= n; i++) dp[i] = -1;
	dp[0] = 0;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		if (dp[mx] <= g[i]) {
			++mx;
			dp[mx] = g[i];
		} else {
			for (int j = mx - 1; j >= 0; j--)
				if (dp[j] <= g[i])
					dp[j + 1] = min(dp[j + 1], g[i]);
		}
	}
	cout << n - mx << '\n';
}

int main() {
	Task();
	Solve();
	cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
	return 37^37;
}

Compilation message

studentsko.cpp: In function 'void Task()':
studentsko.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen(FNAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
studentsko.cpp:22:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   freopen(FNAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 600 KB Output is correct