Submission #827979

#TimeUsernameProblemLanguageResultExecution timeMemory
827979LoboGarden (JOI23_garden)C++17
45 / 100
3065 ms7592 KiB
#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); } for(int x = 0; x < d; x++) sort(all(vals[x])); int ans = inf; for(int y0 = 0; y0 < d; y0++) { set<int> pos; for(int y = 0; y < 2*d; y++) endhere[y].clear(); for(int x = 0; x < d; x++) { while(vals[x].size() && 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); } // cout << y0 << " " << y1 << " " << deltax << " " << pos.size() << " " << vals[0].back() << endl; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...