Submission #1065627

#TimeUsernameProblemLanguageResultExecution timeMemory
1065627crafticatGarden (JOI23_garden)C++17
0 / 100
3064 ms62392 KiB
#include <bits/stdc++.h> using namespace std; #include <bits/stdc++.h> #include <utility> using namespace std; using ll = long long; using pi = pair<int,int>; using pl = pair<ll,ll>; #define temp(T) template<class T> temp(T) using V = vector<T>; using vi = V<int>; using vl = V<ll>; using vvi = V<vi>; using vpi = V<pi>; using vb = V<bool>; using vvb = V<vb>; vi dx = {0,1,-1,0}; vi dy = {1,0,0,-1}; #define sz(x) x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define rep(a) F0R(_,a) #define each(a,x) for (auto& a: x) using str = string; const int MOD = 1e9 + 7; const ll BIG = 1e18; const int INF = 1e9 + 2; temp(T) bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) temp(T) bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } // set a = max(a,b) void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } // FILE I/O void setIn(str s) { freopen(s.c_str(),"r",stdin); } void setOut(str s) { freopen(s.c_str(),"w",stdout); } void setIO(str s = "") { unsyncIO(); if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO } #define read(x) int x; cin >> x temp(T) void pr(T x) { cout << to_string(x); } temp(T) void prln(T x) { cout << to_string(x) << "\n"; } vi readV(int n) { vi input(n); F0R(i,n) cin >> input[i]; return input; } int rand(int a, int b) { return a + rand() % (b - a + 1); } #define gen(x,a,b) int x = rand(a,b) temp(T) void moveAll(V<T> &a, V<T> &b) { each(x,b) { a.pb(x); } b.clear(); } vi genArr(int n, int a, int b) { vi generated(n); F0R(i,n) { generated[i] = rand(a,b); } return generated; } vvi genTree(int n) { vvi g(n + 1); F0R(i,n) { gen(p,0,i); g[p].pb(i + 1); g[i + 1].pb(p); } return g; } vvb readGrid(int a, int b) { vvb grid(a + 2, vb(b + 2, true)); F0R(i, a) { F0R(j, b) { bool k; cin >> k; grid[i + 1][j + 1] = k; } } return grid; } using tup = tuple<int, int, bool>; // x, y, changed V<tup> pos; int d; struct circle { multiset<int> dataPoints; void insert(int x) { dataPoints.ins(x); } void erase(int x) { dataPoints.erase(dataPoints.find(x)); } int query() { if (dataPoints.empty()) return 0; int l = *dataPoints.rbegin(); int best = 0; each(x, dataPoints) { ckmax(best, (x - l + d - 1) % d); l = x; } return d - best; } void clear() { dataPoints.clear(); } }; set<tup> elm; queue<tup> reqRemoved; int imp = 0; circle c; void addCur(tup x) { reqRemoved.emplace(x); imp += get<2>(x); c.insert(get<1>(x)); } void remCur() { c.erase(get<1>(reqRemoved.front())); imp -= get<2>(reqRemoved.front()); reqRemoved.pop(); } void removeFrom(int l, int r) { auto a = elm.lower_bound({l,0,0}); while (a != elm.end() && get<0>(*a) < r) { addCur(*a); elm.erase(a); a = elm.lower_bound({l,0,0}); } } void reset() { c.clear(); elm.clear(); imp = 0; reqRemoved = queue<tup>(); } int findOpt(int w) { reset(); int best = INF; each(v, pos) { auto [x, y, changed] = v; if (changed) c.insert(y); elm.ins(v); } each(v, pos) { auto [x, y, changed] = v; int l = x - w; if (l < 0) { l += d; removeFrom(l, 1e9); removeFrom(0, x); } else { removeFrom(l, x); } while (!reqRemoved.empty() && (x - get<0>(reqRemoved.front()) + d) % d > w) { remCur(); } if (imp == 0) ckmin(best, c.query()); } return best; } int main() { setIO(); int n, m; cin >> n >> m >> d; F0R(i, n) { int x, y; cin >> x >> y; pos.pb({x % d,y % d,true}); } F0R(i, m) { int x, y; cin >> x >> y; pos.pb({x % d,y % d,false}); } sort(all(pos)); ll ans = ll(INF) * ll(INF) ; FOR(i,0, d) { if (i == 50) { int stop = 25; } ckmin(ans, ll(findOpt(i)) * ll(d - (i))); } cout << ans; return 0; }

Compilation message (stderr)

garden.cpp: In function 'int main()':
garden.cpp:238:17: warning: unused variable 'stop' [-Wunused-variable]
  238 |             int stop = 25;
      |                 ^~~~
garden.cpp: In function 'void setIn(str)':
garden.cpp:59:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
garden.cpp: In function 'void setOut(str)':
garden.cpp:60:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...