# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282191 |
2020-08-24T06:14:31 Z |
임성재(#5755) |
Abduction 2 (JOI17_abduction2) |
C++17 |
|
154 ms |
37232 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9 + 7;
const ll INF = 1e18;
int n, m, q;
int a[50010];
int b[50010];
vector<pii> v;
int ans[2][2010][2010];
bool chk[100010];
int main() {
fast;
cin >> n >> m >> q;
for(int i=1; i<=n; i++) {
cin >> a[i];
v.eb(a[i], i);
}
for(int i=1; i<=m; i++) {
cin >> b[i];
v.eb(b[i], i+n);
}
sort(all(v));
reverse(all(v));
for(int i=1; i<=n; i++) {
for(int j=1; b[j] < a[i] && j <= m; j++) {
ans[0][i][j] = max(ans[0][i][j], j-1);
}
for(int j = m; b[j] < a[i] && j>=1; j--) {
ans[0][i][j] = max(ans[0][i][j], m - j);
}
}
for(int i=1; i<=m; i++) {
for(int j=1; a[j] < b[i] && j<=n; j++) {
ans[1][j][i] = max(ans[1][j][i], j-1);
}
for(int j = n; a[j] < b[i] && j>=1; j--) {
ans[1][j][i] = max(ans[1][j][i], n - j);
}
}
for(auto x : v) {
chk[x.se] = true;
if(x.se <= n) {
for(int i=1; i<=m; i++) {
if(a[x.se] < b[i]) continue;
for(int j = x.se + 1; a[j] < b[i] && j<=n; j++) {
ans[1][j][i] = max(ans[1][j][i], ans[0][x.se][i] + j - x.se);
}
for(int j = x.se - 1; a[j] < b[i] && j>=1; j--) {
ans[1][j][i] = max(ans[1][j][i], ans[0][x.se][i] + x.se - j);
}
}
}
else{
for(int i=1; i<=n; i++) {
if(b[x.se-n] < a[i]) continue;
for(int j = x.se - n + 1; b[j] < a[i] && j<=m; j++) {
ans[0][i][j] = max(ans[0][i][j], ans[1][i][x.se-n] + j - x.se + n);
}
for(int j = x.se - n - 1; b[j] < a[i] && j>=0; j--) {
ans[0][i][j] = max(ans[0][i][j], ans[1][i][x.se-n] + x.se - n - j);
}
}
}
}
while(q--) {
int x, y;
cin >> x >> y;
int ret = 0;
for(int i=x+1; i<=n; i++) {
ret = max(ret, abs(i - x) + ans[0][i][y]);
if(b[y] < a[i]) break;
}
for(int i=x-1; i>=1; i--) {
ret = max(ret, abs(i - x) + ans[0][i][y]);
if(b[y] < a[i]) break;
}
for(int i=y+1; i<=m; i++) {
ret = max(ret, abs(i - y) + ans[1][x][i]);
if(a[x] < b[i]) break;
}
for(int i=y-1; i>=1; i--) {
ret = max(ret, abs(i - y) + ans[1][x][i]);
if(a[x] < b[i]) break;
}
cout << ret << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
154 ms |
31868 KB |
Output is correct |
13 |
Correct |
144 ms |
31992 KB |
Output is correct |
14 |
Correct |
144 ms |
31868 KB |
Output is correct |
15 |
Correct |
142 ms |
31864 KB |
Output is correct |
16 |
Correct |
147 ms |
31864 KB |
Output is correct |
17 |
Correct |
63 ms |
28152 KB |
Output is correct |
18 |
Correct |
60 ms |
28152 KB |
Output is correct |
19 |
Correct |
66 ms |
30076 KB |
Output is correct |
20 |
Correct |
64 ms |
29304 KB |
Output is correct |
21 |
Correct |
80 ms |
30328 KB |
Output is correct |
22 |
Correct |
70 ms |
30072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
154 ms |
31868 KB |
Output is correct |
13 |
Correct |
144 ms |
31992 KB |
Output is correct |
14 |
Correct |
144 ms |
31868 KB |
Output is correct |
15 |
Correct |
142 ms |
31864 KB |
Output is correct |
16 |
Correct |
147 ms |
31864 KB |
Output is correct |
17 |
Correct |
63 ms |
28152 KB |
Output is correct |
18 |
Correct |
60 ms |
28152 KB |
Output is correct |
19 |
Correct |
66 ms |
30076 KB |
Output is correct |
20 |
Correct |
64 ms |
29304 KB |
Output is correct |
21 |
Correct |
80 ms |
30328 KB |
Output is correct |
22 |
Correct |
70 ms |
30072 KB |
Output is correct |
23 |
Runtime error |
82 ms |
37232 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
31864 KB |
Output is correct |
2 |
Correct |
151 ms |
31864 KB |
Output is correct |
3 |
Correct |
153 ms |
31864 KB |
Output is correct |
4 |
Correct |
148 ms |
31864 KB |
Output is correct |
5 |
Correct |
145 ms |
31864 KB |
Output is correct |
6 |
Correct |
65 ms |
28152 KB |
Output is correct |
7 |
Correct |
62 ms |
28028 KB |
Output is correct |
8 |
Correct |
68 ms |
30076 KB |
Output is correct |
9 |
Correct |
79 ms |
29536 KB |
Output is correct |
10 |
Correct |
63 ms |
30100 KB |
Output is correct |
11 |
Correct |
81 ms |
30072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
154 ms |
31868 KB |
Output is correct |
13 |
Correct |
144 ms |
31992 KB |
Output is correct |
14 |
Correct |
144 ms |
31868 KB |
Output is correct |
15 |
Correct |
142 ms |
31864 KB |
Output is correct |
16 |
Correct |
147 ms |
31864 KB |
Output is correct |
17 |
Correct |
63 ms |
28152 KB |
Output is correct |
18 |
Correct |
60 ms |
28152 KB |
Output is correct |
19 |
Correct |
66 ms |
30076 KB |
Output is correct |
20 |
Correct |
64 ms |
29304 KB |
Output is correct |
21 |
Correct |
80 ms |
30328 KB |
Output is correct |
22 |
Correct |
70 ms |
30072 KB |
Output is correct |
23 |
Runtime error |
82 ms |
37232 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |