QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203040 | #2483. Roof Escape | SolitaryDream# | RE | 0ms | 0kb | C++17 | 1.8kb | 2023-10-06 14:53:54 | 2023-10-06 14:53:54 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n, m, sx, sy, ex, ey;
vector<int> mp[N];
inline double Sqr(double x) {
return x * x;
}
inline int Det(int a, int b, int u, int v, int x, int y) {
u -= a; v -= b;
x -= a; y -= b;
return u * y - x * v;
}
signed main() {
scanf("%lld%lld%lld%lld%lld%lld", &n, &m, &sx, &sy, &ex, &ey);
n /= 2; m /= 2;
for (int i = 0; i <= n + 1; ++i) mp[i].resize(m + 2);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
scanf("%lld", &mp[i][j]);
if (sx > ex) {
sx = 2 * n - sx; ex = 2 * n - ex;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (i < n - i + 1) swap(mp[i][j], mp[n - i + 1][j]);
}
if (sy > ey) {
sy = 2 * m - sy; ey = 2 * m - ey;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (j < m - j + 1) swap(mp[i][j], mp[i][m - j + 1]);
}
double ans1 = sqrt(Sqr(sx - ex) + Sqr(sy - ey));
int ans2 = 0;
for (int i = (sx + 1) / 2, j = (sy + 1) / 2; ; ) {
if (i == (ex + 1) / 2 && j == (ey + 1) / 2) break;
int d = Det(sx, sy, 2 * i + 2, 2 * j + 2, ex, ey);
if (d > 0) {
ans2 += abs(mp[i][j] - mp[i][j + 1]);
++j;
} else if (d == 0) {
vector<int> a({mp[i][j], mp[i + 1][j], mp[i][j + 1], mp[i + 1][j + 1]});
sort(a.begin(), a.end());
int h = a[2];
ans2 += abs(mp[i][j] - h) + abs(mp[i + 1][j + 1] - h);
++i; ++j;
} else {
ans2 += abs(mp[i][j] - mp[i + 1][j]);
++i;
}
}
printf("%.10lf\n", ans1 + ans2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 26 1 1 3 25 0 1 0 5 5 5 0 1 2 1 4 1 5 0 0 0 1 0 6 4 3 2 5 4 1 5