이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5;
const int MAXD = 5000;
const ll INF = 1e18;
int N, M, D;
vector<int> A[MAXD*2+10], B[MAXD+10];
int P[MAXD+10], Q[MAXD*2+10];
vector<pii> V[MAXD+10];
set<int> C[MAXD*2+10];
struct Data
{
set<int> S;
multiset<int> S2;
void init()
{
S.clear(); S2.clear();
}
void insert(int x)
{
if(S.count(x)) return;
S.insert(x);
if(S.size()==2)
{
int p=*S.begin(), q=*next(S.begin());
S2.insert(q-p); S2.insert(D+p-q);
}
else if(S.size()>2)
{
auto it=S.find(x);
int p, q;
if(it!=S.begin()) p=*prev(it);
else p=*prev(S.end())-D;
if(next(it)!=S.end()) q=*next(it);
else q=*S.begin()+D;
S2.erase(S2.find(q-p));
S2.insert(x-p); S2.insert(q-x);
}
}
int query()
{
if(S.size()<=1) return 1;
else return D-*prev(S2.end())+1;
}
}DB;
ll ans=INF;
int main()
{
scanf("%d%d%d", &N, &M, &D);
for(int i=1; i<=N; i++)
{
int y, x;
scanf("%d%d", &y, &x);
P[x]=1; Q[y]=1; Q[y+D]=1;
}
for(int i=1; i<=M; i++)
{
int y, x;
scanf("%d%d", &y, &x);
B[x].push_back(y);
}
for(int i=0; i<D; i++)
{
if(B[i].empty()) continue;
sort(B[i].begin(), B[i].end());
B[i].erase(unique(B[i].begin(), B[i].end()), B[i].end());
V[0].push_back({B[i].back(), i});
int t=B[i].back();
for(auto it : B[i])
{
V[it+1].push_back({t, -i});
V[it+1].push_back({it+D, i+1});
t=it+D;
}
}
for(int i=0; i<D; i++)
{
DB.init();
for(int j=0; j<D; j++) if(P[j]) DB.insert(j);
int val=i;
for(int j=D+i-1; j>=val; j--) if(Q[j]) { val=j; break; }
for(auto [y, x] : V[i])
{
if(x>0) C[y].insert(x-1);
else C[y].erase(-x);
}
//printf("?%d\n", val);
for(int j=D+i-1; j>=val; j--)
{
//printf("%d %d : %d\n", i, j, DB.query());
ans=min(ans, (ll)DB.query()*(j-i+1));
for(auto it : C[j]) DB.insert(it);
}
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
garden.cpp: In function 'int main()':
garden.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d%d%d", &N, &M, &D);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
garden.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d%d", &y, &x);
| ~~~~~^~~~~~~~~~~~~~~~
garden.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%d%d", &y, &x);
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |