QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203497 | #2483. Roof Escape | DreamOn# | WA | 1ms | 6268kb | C++23 | 2.7kb | 2023-10-06 17:51:38 | 2023-10-06 17:51:38 |
Judging History
answer
#include <bits/stdc++.h>
#define MP(x, y) make_pair(x, y)
#define pii pair <int, int>
using namespace std;
const double eps = 1e-8;
int read() {
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while('0' <= c && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
#define Maxn 100005
int W, H, Sx, Sy, Ex, Ey;
double ans1, ans2, k, b;
vector <int> t[Maxn];
void calcLine() {
if(Sx == Ex) k = 1926, b = Sx;
else {
k = (Sy - Ey) * 1.0 / (Sx - Ex);
b = Sy - k * Sx;
}
}
int main() {
W = read(); H = read(); Sx = read(); Sy = read(); Ex = read(); Ey = read();
ans1 = sqrt((Sx - Ex) * (Sx - Ex) + (Sy - Ey) * (Sy - Ey));
for(int i = 1; i <= H / 2; ++i) { // Attention it's a (H/2, W/2) matrix!
t[i].push_back(0);
for(int j = 1; j <= W / 2; ++j) t[i].push_back(read());
}
calcLine();
if(Sx > Ex) swap(Sx, Ex), swap(Sy, Ey);
for(double x = Sx + 1, y; x <= Ex - 1; x += 2) {
y = k * x + b;
if(fabs((y / 2) - (int)(y / 2)) > eps) { // Edge
int li = (ceil)(y / 2), lj = x / 2;
int ri = li, rj = lj + 1;
ans2 += fabs(t[li][lj] - t[ri][rj]);
// cerr << "???" << endl;
}
else { // Point
int ai = y / 2, aj = x / 2;
int bi = ai, bj = aj + 1;
int ci = ai + 1, cj = aj;
int di = ai + 1, dj = aj + 1;
int tmp[5] = {0, t[ai][aj], t[bi][bj], t[ci][cj], t[di][dj]};
sort(tmp + 1, tmp + 5);
int maxh = tmp[3];
if(k > 0) ans2 += abs(maxh - t[ai][aj]) + abs(maxh - t[di][dj]);
else ans2 += abs(maxh - t[bi][bj]) + abs(maxh - t[ci][cj]);
// cerr << "plog " << x << " " << y << " " << ans2 << " " << maxh << endl;
// cerr << "qlog " << ai << " " << bi << " " << ci << " " << di << endl;
// cerr << "elog " << aj << " " << bj << " " << cj << " " << dj << endl;
}
}
if(Sy > Ey) swap(Sx, Ex), swap(Sy, Ey);
// cerr << Sx << " " << Sy << " " << Ex << " " << Ey << endl;
for(double y = Sy + 1, x; y <= Ey - 1; y += 2) {
if(k == 1926) x = Sx;
else x = (y - b) / k;
// cerr << "!!!" << x << endl;
if(fabs((x / 2) - (int)(x / 2)) > eps) { // Edge
int ui = (ceil)(x / 2), uj = y / 2;
int di = ui + 1, dj = uj;
ans2 += fabs(t[ui][uj] - t[di][dj]);
// cerr << "???" << endl;
}
}
cout << fixed << setprecision(10);
cout << ans1 + ans2 << endl;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6268kb
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
output:
42.0831891576
result:
wrong answer 1st numbers differ - expected: '53.08319', found: '42.08319', error = '0.20722'