#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H,W,Q;
cin >> H >> W >> Q;
vector<int> A(H+1);
for(int i=1;i<=H;i++)cin>>A[i];
vector<int> B(W+1);
for(int i=1;i<=W;i++)cin>>B[i];
for(int i=1;i<=Q;i++) {
int s,t;cin>>s>>t;
int ans = 0;
function<void(int,int,int,int,int)> dfs = [&](int x,int y,int dist,int parx,int pary) {
if(x<1 or x>H or y<1 or y>W)return;
ans=max(ans,dist);
if(A[x]>B[y]) {
if(x!=parx or y-1!=pary)dfs(x,y-1,dist+1,x,y);
if(x!=parx or y+1!=pary)dfs(x,y+1,dist+1,x,y);
} else {
if(x+1!=parx or y!=pary)dfs(x+1,y,dist+1,x,y);
if(x-1!=parx or y!=pary)dfs(x-1,y,dist+1,x,y);
}
};
dfs(s,t,0,-1,-1);
if(A[s]>B[t]) {
dfs(s-1,t,1,s,t);
dfs(s+1,t,1,s,t);
} else {
dfs(s,t-1,1,s,t);
dfs(s,t+1,1,s,t);
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
1116 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
4 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1040 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
14 ms |
1372 KB |
Output is correct |
19 |
Execution timed out |
5075 ms |
11272 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
1116 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
4 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1040 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
14 ms |
1372 KB |
Output is correct |
19 |
Execution timed out |
5075 ms |
11272 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4363 ms |
2044 KB |
Output is correct |
2 |
Correct |
2206 ms |
1772 KB |
Output is correct |
3 |
Correct |
2771 ms |
1676 KB |
Output is correct |
4 |
Correct |
3112 ms |
1624 KB |
Output is correct |
5 |
Correct |
4302 ms |
1880 KB |
Output is correct |
6 |
Correct |
2757 ms |
1884 KB |
Output is correct |
7 |
Correct |
2454 ms |
1876 KB |
Output is correct |
8 |
Execution timed out |
5022 ms |
10288 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
1116 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
4 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1040 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
14 ms |
1372 KB |
Output is correct |
19 |
Execution timed out |
5075 ms |
11272 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |