This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
const int N = 307;
int n, m;
int k;
array<int, 2> a[N];
vector<int> b[N];
array<int, 3> c[N];
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> m >> k;
vector<int> v;
for (int i = 1; i <= k; i++) {
cin >> a[i][0] >> a[i][1];
v.push_back(a[i][0]);
}
sort(all(v));
v.erase(unique(all(v)), v.end());
int l = v.size();
auto get = [&](int x) {
return lower_bound(all(v), x) - v.begin();
};
for (int i = 1; i <= k; i++) {
b[get(a[i][0])].push_back(a[i][1]);
}
for (int i = 0; i < l; i++) {
sort(all(b[i]));
c[i][0] = b[i].front() - 1;
c[i][1] = m - b[i].back();
for (int j = 1; j < b[i].size(); j++) {
c[i][2] = max(c[i][2], b[i][j] - b[i][j - 1] - 1);
}
}
ll ans = 1e18;
auto check = [&](int p, int q) {
vector<int> d;
for (int i = 0; i < l; i++) {
if (p >= c[i][0] && q >= c[i][1] && p + q >= c[i][2]) {
d.push_back(v[i]);
}
}
if (d.empty())
return;
int s = d.front() - 1, t = n - d.back(), gap = 0;
for (int i = 1; i < d.size(); i++) {
gap = max(gap, d[i] - d[i - 1] - 1);
}
ans = min(ans, 0LL + p + q + max(s + t, gap));
};
for (int i = 0; i < l; i++) {
for (int j = 0; j < l; j++) {
check(c[i][0], c[j][1]);
if (c[j][2] >= c[i][0])
check(c[i][0], c[j][2] - c[i][0]);
}
}
for (int i = 0; i < 50; i++)
for (int j = 0; j < 50; j++)
check(i, j);
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
cultivation.cpp: In function 'int main()':
cultivation.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int j = 1; j < b[i].size(); j++) {
| ~~^~~~~~~~~~~~~
cultivation.cpp: In lambda function:
cultivation.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 1; i < d.size(); i++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |