QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550729#2483. Roof EscapeXfJbUhpyzgaWWA 1ms6200kbC++142.2kb2024-09-07 14:04:502024-09-07 14:04:50

Judging History

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

  • [2024-09-07 14:04:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6200kb
  • [2024-09-07 14:04:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using pi = pair<int, int>;
const int N = 100100;
int w, h, sx, sy, ex, ey;
vector<int> a[N];

void foo(double x1, double y1, double x2, double y2) {

}

int main() {
    cin >> w >> h >> sx >> sy >> ex >> ey;
    if (sx > ex) swap(sx, ex), swap(sy, ey);
    for (int i = 0; i <= h / 2 + 1; i++)
        a[i].resize(w / 2 + 2);
    for (int i = 1; i <= h / 2; i++)
        for (int j = 1; j <= w / 2; j++)
            cin >> a[i][j];
    if (sy > ey) {
        swap(sy, ey);
        reverse(a + 1, a + h / 2 + 1);
    }
    
    int ans = 0;

    double x = sx - ex, y = sy - ey, len = sqrt(x * x + y * y);
    
    if (sx == ex) {
        int last = -1;
        for (int y = sy; y <= ey; y += 2) {
            int i = sx / 2 + 1, j = y / 2 + 1;
            if (last != -1) ans += abs(last - a[j][i]);
            last = a[j][i];
        }
        cout << fixed << setprecision(12) << ans + len << "\n";
        return 0;
    }

    //cout << sx << " " << sy << " " << ex << " " << ey << "\n";

    vector<int> lower = {sy}, upper;
    for (int x = sx + 1; x < ex; x += 2) {
        long long A = 1ll * (ey - sy) * (x - sx), B = ex - sx;
        lower.push_back(sy + A / B - (A < 0 && A % B));
        upper.push_back(sy + A / B + (A > 0 && A % B));
    }
    upper.push_back(ey);


    for (int i = 0; i < lower.size(); i++) {
        lower[i] = lower[i] / 2 + 1;
        upper[i] = (upper[i] + 1) / 2 + 1;
        for (int j = lower[i]; j < upper[i] - 1; j++)
            ans += abs(a[j + 1][i + sx / 2 + 1] - a[j][i + sx / 2 + 1]);
    }

    for (int i = 1; i < lower.size(); i++) {
        if (lower[i] == upper[i - 1]) {
            int j = upper[i - 1];
            int A = a[j - 1][i - 1 + sx / 2 + 1];
            int B = a[j][i - 1 + sx / 2 + 1];
            int C = a[j - 1][i + sx / 2 + 1];
            int D = a[j][i + sx / 2 + 1];
            ans += min(abs(A - B) + abs(D - B), abs(A - C) + abs(D - C));
        } else {
            ans += abs(a[lower[i]][i + sx / 2 + 1] - a[lower[i]][i - 1 + sx / 2 + 1]);
        }
    }

    cout << fixed << setprecision(12) << ans + len << "\n";
    return 0;
} 

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 6140kb

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:

53.083189157585

result:

ok found '53.08319', expected '53.08319', error '0.00000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6200kb

input:

8 8 1 7 7 1
2 3 2 0
2 1 1 2
1 2 0 0
0 0 0 1

output:

14.485281374239

result:

ok found '14.48528', expected '14.48528', error '0.00000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 6176kb

input:

2 2 1 1 1 1
100

output:

0.000000000000

result:

ok found '0.00000', expected '0.00000', error '-0.00000'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 6120kb

input:

4 4 1 1 3 3
100 1
1 100

output:

200.828427124746

result:

wrong answer 1st numbers differ - expected: '2.82843', found: '200.82843', error = '70.00357'