QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203448#2483. Roof EscapeDreamOn#WA 1ms6020kbC++232.5kb2023-10-06 17:31:452023-10-06 17:31:46

Judging History

你现在查看的是最新测评结果

  • [2023-10-06 17:31:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6020kb
  • [2023-10-06 17:31:45]
  • 提交

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(abs((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 maxh = max(max(t[ai][aj], t[bi][bj]), max(t[ci][cj], t[di][dj]));
            if(k > 0) ans2 += (maxh - t[ai][aj]) + (maxh - t[di][dj]);
            else ans2 += (maxh - t[bi][bj]) + (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 > Ex) swap(Sx, Ex), swap(Sy, Ey);
    for(double y = Sy + 1, x; y <= Ey - 1; y += 2) {
        if(k == 1926) x = Sx;
        else x = (y - b) / k;
        if(abs((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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6020kb

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:

29.0831891576

result:

wrong answer 1st numbers differ - expected: '53.08319', found: '29.08319', error = '0.45212'