Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <cmath>
- #include <map>
- using namespace std;
- int main() {
- int n, m;
- cin >> n >> m;
- int si, sj;
- cin >> si >> sj;
- si--;
- sj--;
- vector<vector<int>> mat(n, vector<int>(m, 0));
- vector<vector<bool>> visited(n, vector<bool>(m, false));
- visited[si][sj] = true;
- queue<int> q;
- q.push(si);
- q.push(sj);
- q.push(0);
- int di[] = {-1, 1, 0, 0};
- int dj[] = {0, 0, -1, 1};
- int max_ucenik = 0;
- while(!q.empty()) {
- int ci = q.front();
- q.pop();
- int cj = q.front();
- q.pop();
- int ucenik = q.front();
- q.pop();
- max_ucenik = max(max_ucenik, ucenik);
- mat[ci][cj] = ucenik;
- for(int i = 0; i < 4; i++) {
- int ti = ci + di[i];
- int tj = cj + dj[i];
- if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj]) {
- q.push(ti);
- q.push(tj);
- q.push(ucenik + 1);
- visited[ti][tj] = true;
- }
- }
- }
- int cnt = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] == max_ucenik) {
- cnt++;
- }
- }
- }
- cout << max_ucenik << " " << cnt << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement