QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#557106 | #360. Cultivation | makrav | 0 | 0ms | 3548kb | C++20 | 2.5kb | 2024-09-11 03:17:09 | 2024-09-11 03:17:09 |
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
void solve() {
int h, w, n; cin >> h >> w >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {cin >> a[i].first >> a[i].second; a[i].first--; a[i].second--; }
int ans = 1e9;
vector<int> ups, dwns;
for (int i = 0; i < n; i++) ups.pb(a[i].first - 1);
for (int i=0;i<n;i++)dwns.pb(h-a[i].first);
sort(all(ups));reverse(all(ups));sort(all(dwns)); reverse(all(dwns));
for (int up : ups) {
if (up>ans)continue;
for (int down : dwns) {
if (up+down>ans)continue;
for (int left=0;left<w;left++) {
if (up+left+down>ans)continue;
for (int right = 0;right<w;right++) {
if (up+left+right+down>ans)continue;
vector<vector<int>> us(h+1, vector<int>(w+1));
for (int i = 0; i < n; i++) {
int I1 = max(0, a[i].first - up), I2 = min(h - 1, a[i].first + down), J1 = max(0, a[i].second - left), J2 = min(w - 1, a[i].second + right);
us[I1][J1]++;
us[I1][J2 + 1]--;
us[I2 + 1][J1]--;
us[I2 + 1][J2 + 1]++;
}
//cout<<up<<' '<<down<<' '<<left<<' '<<right<<'\n';
bool good = true;
if (!us[0][0]) continue;
for (int i = 0; i < n; i++) {
if(!good)break;
for (int j = 0; j < w; j++) {
if (i > 0) us[i][j] += us[i - 1][j];
if (j > 0) us[i][j] += us[i][j - 1];
if (i>0&&j>0) us[i][j] -= us[i-1][j-1];
if (us[i][j]==0) {
good=false;break;
}
}
}
if(good)ans=min(ans,up+down+left+right);
}
}
}
}
cout << ans << '\n';
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out1.txt", "w", stdout);
cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3548kb
input:
2 4 2 1 1 1 4
output:
1000000000
result:
wrong answer 1st lines differ - expected: '3', found: '1000000000'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Memory Limit Exceeded
Test #45:
score: 0
Memory Limit Exceeded
input:
1000000000 1000000000 17 822413671 70423910 260075513 431043546 300945721 793553248 142848049 163787897 392462410 831950868 699005697 111397300 444396260 130450496 642691616 595456084 467968916 463598810 159764248 611476406 929313754 539645102 365153650 964108073 906780716 373514044 970118116 655138...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%