CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Anniiiz
Submission time:2020-09-29 15:19:36 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int minimimatka(int*, int*, int)':
input/code.cpp:37:13: error: 'class std::queue<paikka>' has no member named 'isEmpty'; did you mean 'empty'?
   while (!q.isEmpty()) {
             ^~~~~~~
             empty
input/code.cpp:45:26: error: 'N' was not declared in this scope
       if (laudalla(x, y, N) && !kayty[x][y]) {
                          ^
input/code.cpp: At global scope:
input/code.cpp:52:9: error: cannot declare '::main' to be a global variable
 int main(
         ^
input/code.cpp:54:3: error: expected primary-expression before 'int'
   int n;
   ^~~
input/code.cpp:54:3: error: expected '}' before 'int'
input/code.cpp:54:3: error: expected ')' before 'int'
input/code.cpp:55:3: error: 'cin' does not name a type; did you mean 'sin'?
   cin >> n;
   ^~~
   sin
input/code.cpp:57:3: error: expected unqualified-id before 'for'
   for (int i = 1; i < n + 1; i++) {
   ^~~
input/code.cpp:57:19: error: 'i' does not name a type
   for (int i = 1; i < n + 1;...

Code

#include <bits/stdc++.h>

using namespace std;


struct paikka {
  int x, y;
  int matka;
  paikka() {}
  paikka(int x, int y, int matka)
    : x(x), y(y), matka(matka)
  {
  }
};


bool laudalla(int x, int y, int n)
{
  if (x >= 1 && x <= n && y >= 1 && y <= n)
    return true;
  return false;
}

int minimimatka(int heppa[], int maali[], int n)
{
  int x_vaihtoehto[] = { 1, 1, -1, -1, 2, 2, -2, -2 };
  int y_vaihtoehto[] = { 2, -2, 2, -2, 1, -1, 1, -1 };
  queue<paikka> q;
  q.push(paikka(heppa[0], heppa[1], 0));
  paikka a;
  int x, y;
  bool kayty[n+1][n+1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      kayty[i][j] = false;
  kayty[heppa[0]][heppa[1]] = true;
  while (!q.isEmpty()) {
    a = q.front();
    q.pop();
    if (a.x == maali[0] && a.y == maali[1])
      return a.matka;
    for (int i = 0; i < 8; i++) {
      x = a.x + x_vaihtoehto[i];
      y = a.y + y_vaihtoehto[i];
      if (laudalla(x, y, N) && !kayty[x][y]) {
        kayty[x][y] = true;
        q.push(paikka(x, y, a.matka + 1));
      }
    }
  }
}
int main(
{
  int n;
  cin >> n;
  int heppa[] = { 1, 1 };
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; i < n +1; j++) {
      int maali[] = { i, j };
      cout << minimimatka(heppa, maali, 0);
    }
    cout << "\n";
  }
  return 0;
}