이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const long long inf = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1e4+10;
int n, m, d, hasp[maxn], hasq[maxn];
deque<int> vals[maxn];
vector<int> endhere[maxn];
void solve() {
cin >> n >> m >> d;
for(int i = 1; i <= n; i++) {
int x,y; cin >> x >> y;
hasp[x]++; hasp[x+d]++;
hasq[y]++; hasq[y+d]++;
}
for(int i = 1; i <= m; i++) {
int x,y; cin >> x >> y;
if(hasp[x]) continue;
vals[x].pb(y);
}
int ans = inf;
for(int y0 = 0; y0 < d; y0++) {
set<int> pos;
for(int y = 0; y < d; y++) endhere[y].clear();
for(int x = 0; x < d; x++) {
if(vals[x].front() == y0-1) {
vals[x].pop_front();
vals[x].pb(y0-1+d);
}
if(hasp[x]) pos.insert(x);
else if(vals[x].size()) {
endhere[vals[x].back()].pb(x);
pos.insert(x);
}
}
int qtdq = 0;
for(int y1 = y0; y1 < y0+d; y1++) {
qtdq+= hasq[y1];
for(auto x : endhere[y1]) {
pos.erase(x);
}
if(qtdq != n) continue;
int deltax = *pos.rbegin()-*pos.begin()+1;
for(auto it = pos.begin(); next(it) != pos.end(); it++) {
deltax = min(deltax,d+1-*next(it)+*it);
}
ans = min(ans,deltax*(y1-y0+1));
}
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
# | 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... |