Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Point{
- unsigned long long xx;
- unsigned long long yy;
- };
- int main(){
- std::ios::sync_with_stdio(false);
- unsigned long long W, H, N;
- cin >> W >> H >> N;
- unsigned long long size = W * H;
- if (size > N * 5){
- cout << "No" << endl;
- return 0;
- }
- unsigned long long pointsCount = 0;
- vector<vector<unsigned long>> polotno(W);
- for (unsigned long i = 0; i < W; i++){
- polotno[i].assign(H, 0);
- }
- for (unsigned long i = 0; i < N; i++){
- if ((N - i + 1) * 5 < (size - pointsCount + 1)){
- cout << "No";
- return 0;
- }
- long long x, y;
- cin >> x >> y;
- x--;
- y--;
- vector<Point> points;
- Point p;
- if ((x >= 0) && (x < W) && (y >= 0) && (y < H)){
- p.xx = x;
- p.yy = y;
- points.push_back(p);
- }
- if ((x - 1 >= 0) && (x - 1 < W) && (y >= 0) && (y < H)){
- p.xx = x - 1;
- p.yy = y;
- points.push_back(p);
- }
- if ((x >= 0) && (x < W) && (y - 1 >= 0) && (y - 1 < H)){
- p.xx = x;
- p.yy = y - 1;
- points.push_back(p);
- }
- if ((x + 1 >= 0) && (x + 1 < W) && (y >= 0) && (y < H)){
- p.xx = x + 1;
- p.yy = y;
- points.push_back(p);
- }
- if ((x >= 0) && (x < W) && (y + 1 >= 0) && (y + 1 < H)){
- p.xx = x;
- p.yy = y + 1;
- points.push_back(p);
- }
- for (auto& element : points) {
- if (polotno[element.xx][element.yy] == 0) { //так как считаем с 0 массив, а клетки с 1
- polotno[element.xx][element.yy] = 1;
- pointsCount++;
- }
- }
- }
- if (pointsCount == size){
- cout << "Yes" << endl;
- } else {
- cout << "No" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement