답안 #147258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147258 2019-08-28T14:19:58 Z ipaljak Konj (COCI19_konj) C++14
49 / 70
70 ms 3064 KB
#include <bits/stdc++.h>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long llint;

const int MOD = 1e9 + 7;
const int MAXN = 305;

const int dr[] = {0, -1, 0, 1};
const int ds[] = {1, 0, -1, 0};

int n, D = 300;

char grid[MAXN][MAXN];

void draw(int a, int b, int c, int d) {
  for (int i = min(a, c); i <= max(a, c); ++i)
    for (int j = min(b, d); j <= max(b, d); ++j)
      grid[i][j] = '*';
}

void print() {
  int minr = D, maxr = 0, mins = D, maxs = 0;
  for (int i = 0; i <= D; ++i) {
    for (int j = 0; j <= D; ++j) {
      if (grid[i][j] == '#') {
        minr = min(minr, i);
        maxr = max(maxr, i);
        mins = min(mins, j);
        maxs = max(maxs, j);
      }
    }
  }

  for (int i = minr; i <= maxr; ++i) {
    for (int j = mins; j <= maxs; ++j) {
      if (grid[i][j] == '*') grid[i][j] = '.';
      printf("%c", grid[i][j]);
    }
    printf("\n");
  }
}

inline bool check(int r, int s) {
  return r >= 0 && r <= D && s >= 0 && s <= D && grid[r][s] == '*';
}

int main(void) {
  scanf("%d", &n);
  memset(grid, '.', sizeof grid);
  for (int i = 0; i < n; ++i) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    b = D - b; d = D - d;
    draw(b, a, d, c);
  }

  int r, s;
  scanf("%d%d", &r, &s);
  s = D - s;
  swap(r, s);

  queue<pair<int, int>> Q;
  Q.push({r, s});
  grid[r][s] = '#';

  while (!Q.empty()) {
    auto p = Q.front();
    Q.pop();
    for (int i = 0; i < 4; ++i) {
      int _r = p.first + dr[i];
      int _s = p.second + ds[i];
      if (!check(_r, _s)) continue;
      grid[_r][_s] = '#';
      Q.push({_r, _s});
    }
  }

  print();
  return 0;
}

Compilation message

konj.cpp: In function 'int main()':
konj.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
konj.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &a, &b, &c, &d);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
konj.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &r, &s);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 70 ms 3064 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 1 ms 376 KB Output is correct