답안 #147261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147261 2019-08-28T14:26:29 Z ipaljak Konj (COCI19_konj) C++14
70 / 70
78 ms 760 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 = 605;

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

int n, D = 600;

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 += 2) {
    for (int j = mins; j <= maxs; j += 2) {
      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 / 2 - b; d = D / 2 - d;
    a *= 2; b *= 2; c *= 2; d *= 2;
    draw(b, a, d, c);
  }

  int r, s;
  scanf("%d%d", &r, &s);
  s = D / 2 - s;
  r *= 2; s *= 2;
  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:66: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 632 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 78 ms 760 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 KB Output is correct