18472022-12-05 08:26:45sztomiJegesmedve (50)cpp17Wrong answer 3/507ms5040 KiB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9 + 7;

typedef pair<int, int> pii;

int n, m;
int sor_valt[4]{0, 0, 1, -1};
int oszlop_valt[4]{1, -1, 0, 0};

vector<vector<int>> olvadas;
vector<vector<int>> hal;
vector<vector<int>> fa;

struct comp{
    bool operator()(pii a, pii b){
        return a.first < b.first;
    }
};

int ind(pii kord){
    return kord.first*m + kord.second;
}

pii kord(int ind){
    return {ind/m, ind-ind/m*m};
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    olvadas.assign(n, vector<int>(m));
    hal.assign(n, vector<int>(m));
    pii start;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> olvadas[i][j];
            if(olvadas[i][j] == -1){
                start = {i, j};
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> hal[i][j];
        }
    }

    fa.assign(n*m, vector<int>());
    vector<bool> faban(n*m, false);
    priority_queue<pii, vector<pii>, comp> pq;
    pq.push(make_pair(INF, ind(start)));

    map<int, int> db;

    pii akt;
    while(!pq.empty()){
        akt = pq.top();
        faban[akt.second] = true;
        db[akt.first]++;
        pq.pop();

        pii hely = kord(akt.second);
        for(int i = 0; i < 4; i++){
            pii uj = {hely.first + sor_valt[i], hely.second + oszlop_valt[i]};

            if(uj.first < 0 || uj.first >= n) continue;
            if(uj.second < 0 || uj.second >= m) continue;
            if(faban[ind(uj)]) continue;

            int ertek = min(olvadas[uj.first][uj.second], akt.first);
            faban[ind(uj)] = true;
            pq.push(make_pair(ertek, ind(uj)));
            fa[akt.second].push_back(ind(uj));
        }
    }

    int ki = 0;
    for(auto x : db){
        ki += min(x.first - ki + 1, x.second);
    }
    cout << ki << "\n";

}
SubtaskSumTestVerdictTimeMemory
base3/50
1Accepted0/03ms1824 KiB
2Wrong answer0/02ms2080 KiB
3Accepted3/33ms2488 KiB
4Wrong answer0/33ms2740 KiB
5Wrong answer0/34ms2992 KiB
6Wrong answer0/44ms3564 KiB
7Wrong answer0/32ms3068 KiB
8Wrong answer0/32ms3544 KiB
9Wrong answer0/32ms3420 KiB
10Wrong answer0/42ms3516 KiB
11Wrong answer0/43ms3880 KiB
12Wrong answer0/43ms3676 KiB
13Wrong answer0/43ms3780 KiB
14Wrong answer0/44ms4336 KiB
15Wrong answer0/46ms4608 KiB
16Wrong answer0/47ms5040 KiB