# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
26182 | khsoo01 | Abduction 2 (JOI17_abduction2) | C++11 | 5000 ms | 15960 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
ll h, w, q, a[100005], inv[100005];
ll vis[100005];
set<ll> s;
priority_queue<pair<ll, pair<ll, ll> > > pq[100005];
vector<pair<ll,ll> > ord;
void solve () {
ll X, Y, ret = 0;
scanf("%lld%lld",&X,&Y);
Y += h;
pq[inv[X]].push({0, {X, Y}});
pq[inv[Y]].push({0, {Y, X}});
for(int i=1;i<=h+w;i++) {
s.insert(i);
vis[i] = 0;
}
for(int i=0;i<h+w;i++) {
while(!pq[i].empty()) {
pair<ll,ll> st = pq[i].top().second;
ll val = pq[i].top().first;
pq[i].pop();
if(vis[st.s] == i+1) continue;
vis[st.s] = i+1;
ret = max(ret, val);
auto nxt = s.upper_bound(st.s);
auto prv = s.lower_bound(st.s);
bool f1 = (nxt != s.end() && (*nxt <= h) == (st.s <= h));
bool f2 = (prv != s.begin() && (*(--prv) <= h) == (st.s <= h));
if(!f1) ret = max(ret, val + (st.s <= h ? h : h + w) - st.s);
else pq[inv[*nxt]].push({val + (*nxt) - st.s, {*nxt, st.f}});
if(!f2) ret = max(ret, val + st.s - (st.s <= h ? 1 : h+1));
else pq[inv[*prv]].push({val + st.s - (*prv), {*prv, st.f}});
}
s.erase(ord[i].second);
}
printf("%lld\n",ret);
}
int main()
{
scanf("%lld%lld%lld",&h,&w,&q);
for(int i=1;i<=h+w;i++) {
scanf("%lld",&a[i]);
ord.push_back({a[i], i});
}
sort(ord.begin(), ord.end());
for(int i=0;i<h+w;i++) {
inv[ord[i].second] = i;
}
while(q--) solve();
}
컴파일 시 표준 에러 (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... |