Submission #1276349

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

std::set<std::pair<int, int>> cells;

void init(int R, int C, int sr, int sc, int M, char *S) {
  int x = sr, y = sc;
  cells.insert({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++;
    }
    cells.insert({x, y});
  }
}

int colour(int x1, int y1, int x2, int y2) {
  int V = (x2 - x1 + 1) * (y2 - y1 + 1);
  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++;
  int C0 = 0;
  for (int i = x1; i <= x2; i++) {
    for (int j = y1; j <= y2; j++) {
      if (cells.count({i, j})) {
        C0++;
      }
    }
  }
  // std::cout << V << ' ' << E << ' ' << F << '\n';
  // V + F = E + C + 1 (cred)
  // C = C0 + C1
  return V + F - E - 1 - C0;
}

#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...