CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Anniiiz
Submission time:2020-09-29 15:22:41 +0300
Language:C++11
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1--1, 2, 3details
#2--1, 2, 3details
#3--1, 2, 3details
#4--1, 2, 3details
#5--1, 2, 3details
#6--1, 2, 3details
#7--1, 2, 3details
#8--2, 3details
#9--2, 3details
#10--2, 3details
#11--3details
#12--3details
#13--3details

Compiler report

input/code.cpp: In function 'int minimimatka(int*, int*, int)':
input/code.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

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.empty()) {
    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;
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
4

correct output
0 3 2 5 
3 4 1 2 
2 1 4 3 
5 2 3 2 

user output
(empty)

Test 2

Group: 1, 2, 3

Verdict:

input
5

correct output
0 3 2 3 2 
3 4 1 2 3 
2 1 4 3 2 
3 2 3 2 3 
2 3 2 3 4 

user output
(empty)

Test 3

Group: 1, 2, 3

Verdict:

input
6

correct output
0 3 2 3 2 3 
3 4 1 2 3 4 
2 1 4 3 2 3 
3 2 3 2 3 4 
2 3 2 3 4 3 
...

user output
(empty)

Test 4

Group: 1, 2, 3

Verdict:

input
7

correct output
0 3 2 3 2 3 4 
3 4 1 2 3 4 3 
2 1 4 3 2 3 4 
3 2 3 2 3 4 3 
2 3 2 3 4 3 4 
...

user output
(empty)

Test 5

Group: 1, 2, 3

Verdict:

input
8

correct output
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
...

user output
(empty)

Test 6

Group: 1, 2, 3

Verdict:

input
9

correct output
0 3 2 3 2 3 4 5 4 
3 4 1 2 3 4 3 4 5 
2 1 4 3 2 3 4 5 4 
3 2 3 2 3 4 3 4 5 
2 3 2 3 4 3 4 5 4 
...

user output
(empty)

Test 7

Group: 1, 2, 3

Verdict:

input
10

correct output
0 3 2 3 2 3 4 5 4 5 
3 4 1 2 3 4 3 4 5 6 
2 1 4 3 2 3 4 5 4 5 
3 2 3 2 3 4 3 4 5 6 
2 3 2 3 4 3 4 5 4 5 
...

user output
(empty)

Test 8

Group: 2, 3

Verdict:

input
25

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Test 9

Group: 2, 3

Verdict:

input
49

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Test 10

Group: 2, 3

Verdict:

input
50

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Test 11

Group: 3

Verdict:

input
75

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Test 12

Group: 3

Verdict:

input
99

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Test 13

Group: 3

Verdict:

input
100

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)