Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <queue>
- using namespace std;
- int main() {
- std::ifstream fin("input.txt");
- std::ofstream fout("output.txt");
- short n, m, k;
- fin >> n >> m >> k;
- vector<vector<bool>> map(n, vector<bool> (m, false));
- queue<int> qi, qj;
- int vi, vj;
- vector<int> di = { 0, 0, 1, -1 };
- vector<int> dj = { 1, -1, 0, 0 };
- int max = 0;
- for (int i = 0; i < k; ++i) {
- fin >> vi >> vj;
- vi--; vj--;
- qi.push(vi);
- qj.push(vj);
- map[vi][vj] = true;
- }
- int r = k, sr = 0;
- while (!qi.empty()) {
- vi = qi.front();
- vj = qj.front();
- qi.pop();
- qj.pop();
- for (int i = 0; i < 4; ++i) {
- vi += di[i];
- vj += dj[i];
- if (vi >= 0 && vi < n && vj >= 0 && vj < m) {
- if (map[vi][vj] == false) {
- qi.push(vi);
- qj.push(vj);
- map[vi][vj] = true;
- sr++;
- }
- }
- vi -= di[i];
- vj -= dj[i];
- }
- r--;
- if (r == 0) {
- max++;
- swap(r, sr);
- }
- }
- fout << max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment