#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
typedef array<int, 2> T;
T operator+(T x, T y){
return {x[0] + y[0], x[1] + y[1]};
}
const int mxn = 2000, k = 4;
const T d[k] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int n[2], q;
int a[2][mxn];
int dp[k][mxn][mxn];
bool f(T x){
for(int i = 0; i < 2; i++) if(x[i] < 0 || x[i] >= n[i]) return 0;
return 1;
}
int sol(T x, int y){
int ret = 0, s = 0;
for(; f(x) && a[!(y & 1)][x[!(y & 1)]] > a[y & 1][x[y & 1]]; x = x + d[y]){
ret++;
}
if(!f(x)) return ret;
if(dp[y][x[0]][x[1]]) return dp[y][x[0]][x[1]];
if(a[!(y & 1)][x[!(y & 1)]] < a[y & 1][x[y & 1]]){
for(int i = 0; i < 2; i++){
int z = (y + 2 * i + 1) % k;
s = max(s, sol(x + d[z], z));
}
}
return dp[y][x[0]][x[1]] = ret + s + 1;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n[0] >> n[1] >> q;
for(int i = 0; i < 2; i++)
for(int j = 0; j < n[i]; j++){
cin >> a[i][j];
}
while(q--){
T x;
for(int i = 0; i < 2; i++) cin >> x[i], x[i]--;
int ret = 0;
for(int i = 0; i < k; i++) ret = max(ret, sol(x + d[i], i));
cout << ret << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
6892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |