# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21131 | khsoo01 | Abduction 2 (JOI17_abduction2) | C++11 | 5000 ms | 15960 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
}
Compilation message (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... |