Submission #464708

# Submission time Handle Problem Language Result Execution time Memory
464708 2021-08-13T18:58:06 Z Hamed5001 Cipele (COCI18_cipele) C++14
63 / 90
506 ms 106764 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
/*
	dp[i] = min ugliness if I paired first i shoes
	dp[i] = 
*/
const int mxN = 5010;
int N, M;
vector<int> A1, A2;

void solve1() {
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, abs(A1[i]-A2[i]));
	}
	cout << ans;
}

int dp[mxN][mxN];

int fun(int i, int j) {
	if (i == N)
		return 0;
	if (j == M)
		return INT_MAX;
	int &ret = dp[i][j];
	if (~ret) return ret;

	ret = min(max(abs(A1[i] - A2[j]), fun(i+1, j+1)), fun(i, j+1));
	return ret;
}

void solve2() {
	memset(dp, -1, sizeof dp);
	cout << fun(0, 0);
}

void solve() {
	cin >> N >> M;
	A1.resize(N); A2.resize(M);
	for (auto& a : A1) cin >> a;
	for (auto& a : A2) cin >> a;
	sort(A1.begin(), A1.end());
	sort(A2.begin(), A2.end());

	if (N == M) {
		solve1();
		return;
	}

	if (N > M) {
		swap(N, M);
		swap(A1, A2);
	}

	solve2();
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1100 KB Output is correct
2 Correct 41 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1100 KB Output is correct
2 Correct 41 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 98644 KB Output is correct
2 Correct 459 ms 98960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 98884 KB Output is correct
2 Correct 467 ms 98944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 98952 KB Output is correct
2 Correct 474 ms 98960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 98956 KB Output is correct
2 Correct 461 ms 99072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 459 ms 98892 KB Output is correct
2 Correct 460 ms 98960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 506 ms 106764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 498 ms 106628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 504 ms 106308 KB Output isn't correct
2 Halted 0 ms 0 KB -