Submission #55272

#TimeUsernameProblemLanguageResultExecution timeMemory
55272ksun48Cultivation (JOI17_cultivation)C++14
35 / 100
2063 ms920 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL;; LL r, c, n; vector<pair<LL,LL> > seeds; const LL INF = 2100100100; LL best = INF; set<pair<LL,LL> > tried; void tryx(LL x, LL startx){ if(x < 0 || tried.find({x,startx}) != tried.end()){ return; } LL endx = startx + r - 1; // insert z.second at time z.first // delete at time z.first + x + 1 map<LL, vector<pair<LL, LL> > > events; for(pair<LL,LL> z : seeds){ if(z.first + x < startx || z.first > endx) continue; events[max(z.first, startx)].push_back({0, z.second}); // ins events[min(z.first + x, endx) + 1].push_back({1, z.second}); // del } LL maxup = 0; LL maxdown = 0; LL maxtot = 0; multiset<LL> grass; grass.insert(-1); grass.insert(c); multiset<LL> diffs; diffs.insert(c+1); for(auto x : events){ for(pair<LL,LL> event : x.second){ LL a = event.second; if(event.first == 0){ grass.insert(a); } LL a1 = *(--grass.find(a)); LL a2 = *(++grass.find(a)); if(event.first == 0){ diffs.erase(diffs.find(a2-a1)); diffs.insert(a-a1); diffs.insert(a2-a); } else if(event.first == 1){ diffs.erase(diffs.find(a-a1)); diffs.erase(diffs.find(a2-a)); diffs.insert(a2-a1); } if(event.first == 1){ grass.erase(grass.find(a)); } } if(x.first > endx){ break; } maxtot = max(maxtot, *(--diffs.end()) ); maxup = max(maxup, *(++grass.begin()) - 0); maxdown = max(maxdown, c-1 - *(--(--grass.end())) ); } if(maxtot == c + 1){ return; } best = min(best, max(maxup + maxdown, maxtot - 1) + x); } int main(){ cin >> r >> c >> n; for(LL i = 0; i < n; i++){ LL s, e; cin >> s >> e; s--; e--; seeds.push_back({s,e}); } sort(seeds.begin(), seeds.end()); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ tryx(seeds[i].first + r-1 - seeds[j].first, seeds[i].first); } for(int j = 0; j < n; j++){ for(int k = 0; k < n; k++){ tryx(seeds[j].first - 1 - seeds[k].first, seeds[i].first); } } } cout << best << '\n'; }
#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...