# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21132 | 2017-04-05T02:45:50 Z | khsoo01 | 유괴 2 (JOI17_abduction2) | C++11 | 5000 ms | 15960 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 7496 KB | Output is correct |
2 | Correct | 0 ms | 7496 KB | Output is correct |
3 | Correct | 0 ms | 7496 KB | Output is correct |
4 | Correct | 0 ms | 7496 KB | Output is correct |
5 | Correct | 0 ms | 7496 KB | Output is correct |
6 | Correct | 0 ms | 7496 KB | Output is correct |
7 | Correct | 0 ms | 7496 KB | Output is correct |
8 | Correct | 0 ms | 7496 KB | Output is correct |
9 | Correct | 0 ms | 7496 KB | Output is correct |
10 | Correct | 0 ms | 7496 KB | Output is correct |
11 | Correct | 0 ms | 7496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 7496 KB | Output is correct |
2 | Correct | 0 ms | 7496 KB | Output is correct |
3 | Correct | 0 ms | 7496 KB | Output is correct |
4 | Correct | 0 ms | 7496 KB | Output is correct |
5 | Correct | 0 ms | 7496 KB | Output is correct |
6 | Correct | 0 ms | 7496 KB | Output is correct |
7 | Correct | 0 ms | 7496 KB | Output is correct |
8 | Correct | 0 ms | 7496 KB | Output is correct |
9 | Correct | 0 ms | 7496 KB | Output is correct |
10 | Correct | 0 ms | 7496 KB | Output is correct |
11 | Correct | 0 ms | 7496 KB | Output is correct |
12 | Correct | 3 ms | 7768 KB | Output is correct |
13 | Correct | 3 ms | 7768 KB | Output is correct |
14 | Correct | 0 ms | 7768 KB | Output is correct |
15 | Correct | 3 ms | 7768 KB | Output is correct |
16 | Correct | 6 ms | 7768 KB | Output is correct |
17 | Correct | 3 ms | 7768 KB | Output is correct |
18 | Correct | 0 ms | 7768 KB | Output is correct |
19 | Correct | 0 ms | 7768 KB | Output is correct |
20 | Correct | 3 ms | 7768 KB | Output is correct |
21 | Correct | 3 ms | 7768 KB | Output is correct |
22 | Correct | 0 ms | 7900 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 7496 KB | Output is correct |
2 | Correct | 0 ms | 7496 KB | Output is correct |
3 | Correct | 0 ms | 7496 KB | Output is correct |
4 | Correct | 0 ms | 7496 KB | Output is correct |
5 | Correct | 0 ms | 7496 KB | Output is correct |
6 | Correct | 0 ms | 7496 KB | Output is correct |
7 | Correct | 0 ms | 7496 KB | Output is correct |
8 | Correct | 0 ms | 7496 KB | Output is correct |
9 | Correct | 0 ms | 7496 KB | Output is correct |
10 | Correct | 0 ms | 7496 KB | Output is correct |
11 | Correct | 0 ms | 7496 KB | Output is correct |
12 | Correct | 3 ms | 7768 KB | Output is correct |
13 | Correct | 3 ms | 7768 KB | Output is correct |
14 | Correct | 0 ms | 7768 KB | Output is correct |
15 | Correct | 3 ms | 7768 KB | Output is correct |
16 | Correct | 6 ms | 7768 KB | Output is correct |
17 | Correct | 3 ms | 7768 KB | Output is correct |
18 | Correct | 0 ms | 7768 KB | Output is correct |
19 | Correct | 0 ms | 7768 KB | Output is correct |
20 | Correct | 3 ms | 7768 KB | Output is correct |
21 | Correct | 3 ms | 7768 KB | Output is correct |
22 | Correct | 0 ms | 7900 KB | Output is correct |
23 | Correct | 119 ms | 14244 KB | Output is correct |
24 | Correct | 109 ms | 14244 KB | Output is correct |
25 | Correct | 109 ms | 14244 KB | Output is correct |
26 | Correct | 103 ms | 14244 KB | Output is correct |
27 | Correct | 109 ms | 14244 KB | Output is correct |
28 | Correct | 73 ms | 14244 KB | Output is correct |
29 | Correct | 69 ms | 14244 KB | Output is correct |
30 | Correct | 93 ms | 14508 KB | Output is correct |
31 | Correct | 89 ms | 15960 KB | Output is correct |
32 | Correct | 66 ms | 14244 KB | Output is correct |
33 | Correct | 63 ms | 14244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 99 ms | 7900 KB | Output is correct |
2 | Correct | 96 ms | 7900 KB | Output is correct |
3 | Correct | 93 ms | 7900 KB | Output is correct |
4 | Correct | 96 ms | 7900 KB | Output is correct |
5 | Correct | 93 ms | 7900 KB | Output is correct |
6 | Correct | 66 ms | 7900 KB | Output is correct |
7 | Correct | 63 ms | 7900 KB | Output is correct |
8 | Correct | 93 ms | 8164 KB | Output is correct |
9 | Correct | 96 ms | 8164 KB | Output is correct |
10 | Correct | 96 ms | 8164 KB | Output is correct |
11 | Correct | 93 ms | 8164 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 7496 KB | Output is correct |
2 | Correct | 0 ms | 7496 KB | Output is correct |
3 | Correct | 0 ms | 7496 KB | Output is correct |
4 | Correct | 0 ms | 7496 KB | Output is correct |
5 | Correct | 0 ms | 7496 KB | Output is correct |
6 | Correct | 0 ms | 7496 KB | Output is correct |
7 | Correct | 0 ms | 7496 KB | Output is correct |
8 | Correct | 0 ms | 7496 KB | Output is correct |
9 | Correct | 0 ms | 7496 KB | Output is correct |
10 | Correct | 0 ms | 7496 KB | Output is correct |
11 | Correct | 0 ms | 7496 KB | Output is correct |
12 | Correct | 3 ms | 7768 KB | Output is correct |
13 | Correct | 3 ms | 7768 KB | Output is correct |
14 | Correct | 0 ms | 7768 KB | Output is correct |
15 | Correct | 3 ms | 7768 KB | Output is correct |
16 | Correct | 6 ms | 7768 KB | Output is correct |
17 | Correct | 3 ms | 7768 KB | Output is correct |
18 | Correct | 0 ms | 7768 KB | Output is correct |
19 | Correct | 0 ms | 7768 KB | Output is correct |
20 | Correct | 3 ms | 7768 KB | Output is correct |
21 | Correct | 3 ms | 7768 KB | Output is correct |
22 | Correct | 0 ms | 7900 KB | Output is correct |
23 | Correct | 119 ms | 14244 KB | Output is correct |
24 | Correct | 109 ms | 14244 KB | Output is correct |
25 | Correct | 109 ms | 14244 KB | Output is correct |
26 | Correct | 103 ms | 14244 KB | Output is correct |
27 | Correct | 109 ms | 14244 KB | Output is correct |
28 | Correct | 73 ms | 14244 KB | Output is correct |
29 | Correct | 69 ms | 14244 KB | Output is correct |
30 | Correct | 93 ms | 14508 KB | Output is correct |
31 | Correct | 89 ms | 15960 KB | Output is correct |
32 | Correct | 66 ms | 14244 KB | Output is correct |
33 | Correct | 63 ms | 14244 KB | Output is correct |
34 | Correct | 99 ms | 7900 KB | Output is correct |
35 | Correct | 96 ms | 7900 KB | Output is correct |
36 | Correct | 93 ms | 7900 KB | Output is correct |
37 | Correct | 96 ms | 7900 KB | Output is correct |
38 | Correct | 93 ms | 7900 KB | Output is correct |
39 | Correct | 66 ms | 7900 KB | Output is correct |
40 | Correct | 63 ms | 7900 KB | Output is correct |
41 | Correct | 93 ms | 8164 KB | Output is correct |
42 | Correct | 96 ms | 8164 KB | Output is correct |
43 | Correct | 96 ms | 8164 KB | Output is correct |
44 | Correct | 93 ms | 8164 KB | Output is correct |
45 | Execution timed out | 5000 ms | 14376 KB | Execution timed out |
46 | Halted | 0 ms | 0 KB | - |