(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1065794

#TimeUsernameProblemLanguageResultExecution timeMemory
1065794not_amirGarden (JOI23_garden)C++14
45 / 100
3101 ms27324 KiB
#include <bits/stdc++.h> using namespace std; #define F(x) ((x)<=0)?((x)+d):(x) int main(){ ios_base::sync_with_stdio(false), cin.tie(NULL); int n, m, d; cin >> n >> m >> d; vector<bool> req_x(d); vector<int> prv_s(d, -1), req_y(d); vector<vector<bool> > grid(d, vector<bool>(d)); for(int i = 0; i < n; i++){ int p, q; cin >> p >> q; req_x[p] = 1; req_y[q] = 1; } for(int i = 0; i < m; i++){ int r, s; cin >> r >> s; grid[r][s] = 1; prv_s[s] = r; } int ans = d*d; vector<vector<int> > rx_s(2*d); for(int lx = 0; lx < d; lx++){ for(int y = 0; y < d; y++) if(grid[(lx + d - 1) % d][y]) prv_s[y] = lx + d - 1; for(int y = 0; y < d; y++) if(prv_s[y] != -1) rx_s[prv_s[y]].push_back(y); vector<int> ry = req_y, prv_y(d, -1), nxt_y(d, -1); int maxdiff = 0, rx = lx + d; while(rx > lx && !req_x[(rx-1) % d]) for(int y : rx_s[--rx]) ry[y]++; vector<int> ry_w; for(int y = 0; y < d; y++) if(ry[y]) ry_w.push_back(y); for(int i = 0; i < ry_w.size(); i++){ int a = ry_w[i]; int b = ry_w[(i+1) % ry_w.size()]; prv_y[b] = a; nxt_y[a] = b; } for(int y : ry_w) maxdiff = max(maxdiff, F(nxt_y[y] - y)); for(;rx < lx + d;rx++){ ans = min(ans, (d - (maxdiff - 1)) * (rx - lx)); for(int y : rx_s[rx]) if(--ry[y] == 0){ maxdiff = max(maxdiff, F(nxt_y[y] - prv_y[y])); prv_y[nxt_y[y]] = prv_y[y]; nxt_y[prv_y[y]] = nxt_y[y]; } } ans = min(ans, (d - (maxdiff-1)) * (rx - lx)); } cout << ans << '\n'; }

Compilation message (stderr)

garden.cpp: In function 'int main()':
garden.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(int i = 0; i < ry_w.size(); i++){
      |                  ~~^~~~~~~~~~~~~
#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...