| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1065735 | not_amir | Garden (JOI23_garden) | C++14 | 3097 ms | 27204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#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<pii> pq(n), rs(m);
vector<bool> req_x(d), req_y(d);
vector<int> prv_s(d, -1);
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;
pq[i] = {p, q};
}
for(int i = 0; i < m; i++){
int r, s;
cin >> r >> s;
grid[r][s] = 1;
prv_s[s] = r;
rs[i] = {r, s};
}
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(d), prv_y(d, -1), nxt_y(d, -1);
for(int i = 0; i < d; i++)
ry[i] += req_y[i];
int maxdiff = 0, rx = lx + d;
while(rx > lx){
if(req_x[(rx-1) % d]) break;
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';
}컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
