161732025-04-09 08:19:47RRoli2015. októbercpp17Wrong answer on test 11ms316 KiB
#include <bits/stdc++.h>
using namespace std;

struct Bencu{
    int x1, y1, x2, y2, tav;
};

int n, m, a[800][800], lk[800][800], x, y;
bool sz[800][800], van[800][800];
vector<Bencu> el;

void behuz(int x, int y) {
    if(x-1 >= 0 && !van[x-1][y]) {
        Bencu szom = {x, y, x-1, y, 0};
        szom.tav = abs(a[x][y] - a[x-1][y]);
        el.push_back(szom);
        van[x-1][y] = true;
    }
    if(x+1 < n && !van[x+1][y]) {
        Bencu szom = {x, y, x+1, y, 0};
        szom.tav = abs(a[x][y] - a[x+1][y]);
        el.push_back(szom);
        van[x+1][y] = true;
    }
    if(y-1 >= 0 && !van[x][y-1]) {
        Bencu szom = {x, y, x, y-1, 0};
        szom.tav = abs(a[x][y] - a[x][y-1]);
        el.push_back(szom);
        van[x][y-1] = true;
    }
    if(y+1 < m && !van[x][y+1]) {
        Bencu szom = {x, y, x, y+1, 0};
        szom.tav = abs(a[x][y] - a[x][y+1]);
        el.push_back(szom);
        van[x][y+1] = true;
    }
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j];
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {
        cin >> sz[i][j];
        if(sz[i][j]) {
            x = i;
            y = j;
        }
        lk[i][j] = -1;
    }

    lk[x][y] = 0;
    behuz(x, y);
    while(el.size() > 0) {
        int lk_ert = el[0].tav, lk_ind = 0;
        for(int i = 1; i < el.size(); i++) {
            if(el[i].tav < lk_ert) {
                lk_ert = el[i].tav;
                lk_ind = i;
            }
        }
        lk[el[lk_ind].x2][el[lk_ind].y2] = el[lk_ind].tav;

        int X = el[lk_ind].x2, Y = el[lk_ind].y2;
        for(int i = lk_ind; i < el.size()-1; i++) el[i] = el[i+1];
        el.pop_back();

        behuz(X, Y);
        for(auto i : el) cout << i.x1 << ' ' << i.x2 << '\n';
        cout << '\n';
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) cout << lk[i][j] << ' ';
        cout << '\n';
    }

	return 0;
}
1 - Wrong answer
Memory: 316KiB
Time: 1ms

Program's output:
2 1
2 1
2 2
2 2

2 1
2 1
2 2
2 1
2 2

2 1
2 1
2 1
2 2

2 1
2 1
2...
Expected output:
21
Checker output:
wrong answer 1st numbers differ - expected: '21', found: '2'