Submission #1276353

#TimeUsernameProblemLanguageResultExecution timeMemory
1276353LucaLucaMLand of the Rainbow Gold (APIO17_rainbow)C++20
0 / 100
3095 ms5012 KiB
#include "rainbow.h"
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <set>

namespace {
  std::set<std::pair<int, int>> cells;
  int minX, maxX, minY, maxY;
};

void init(int R, int C, int sr, int sc, int M, char *S) {
  int x = sr, y = sc;
  auto add = [&](int x, int y) {
    cells.insert({x, y});
    minX = std::min(minX, x);
    maxX = std::max(maxX, x);
    minY = std::min(minY, y);
    maxY = std::max(maxY, y);
  };
  add(x, y);
  for (int i = 0; i < M; i++) {
    if (S[i] == 'N') {
      x--;
    } else if (S[i] == 'S') {
      x++;
    } else if (S[i] == 'W') {
      y--;
    } else {
      y++;
    }
    add(x, y);
  }
}

int colour(int x1, int y1, int x2, int y2) {
  int V = 0;
  for (int i = x1; i <= x2; i++) {
    for (int j = y1; j <= y2; j++) {
      if (!cells.count({i, j})) {
        V++;
      }
    }
  }
  int E = 0;
  for (int i = x1; i <= x2; i++) {
    for (int j = y1; j < y2; j++) {
      if (!cells.count({i, j}) && !cells.count({i, j + 1})) {
        E++;
      }
    }
  }
  for (int i = x1; i < x2; i++) {
    for (int j = y1; j <= y2; j++) {
      if (!cells.count({i, j}) && !cells.count({i + 1, j})) {
        E++;
      }
    }
  }
  int F = 0;
  for (int i = x1; i < x2; i++) {
    for (int j = y1; j < y2; j++) {
      if (!cells.count({i, j}) && !cells.count({i, j + 1}) && !cells.count({i + 1, j}) && !cells.count({i + 1, j + 1})) {
        F++;
      }
    }
  }
  F++;
  if (x1 < minX && maxX < x2 && y1 < minY && maxY < y2) {
    F++;
  }
  // std::cout << V << ' ' << E << ' ' << F << '\n';
  // V + F = E + C + 1 (cred)
  return V + F - E - 1;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...