CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:anton7r
Submission time:2020-10-10 00:47:58 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED27
#2ACCEPTED31
#3ACCEPTED42
Test results
testverdicttimegroup
#1ACCEPTED0.15 s1, 2, 3details
#2ACCEPTED0.16 s1, 2, 3details
#3ACCEPTED0.15 s1, 2, 3details
#4ACCEPTED0.16 s1, 2, 3details
#5ACCEPTED0.16 s1, 2, 3details
#6ACCEPTED0.17 s1, 2, 3details
#7ACCEPTED0.17 s1, 2, 3details
#8ACCEPTED0.23 s2, 3details
#9ACCEPTED0.28 s2, 3details
#10ACCEPTED0.27 s2, 3details
#11ACCEPTED0.35 s3details
#12ACCEPTED0.46 s3details
#13ACCEPTED0.47 s3details

Code

import com.sun.tools.jconsole.JConsoleContext;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Main {

    private static int koko = 0;
    private static int i = 0;

    private static Map<Coords, Integer> lauta = new HashMap<>();

    private static Map<Coords, Integer> uudet;

    static class Coords {
        public int x;
        public int y;

        public Coords(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public boolean equals(Object o) {
            Coords c = (Coords)o;
            return c.x==x && c.y==y;
        }

        public void move(int x, int y) {
            x += this.x;
            y += this.y;

            //varmistaa että siirto on mahdollinen
            if(x > -1 && x < koko && y > -1 && y < koko) {
                Coords siirto = new Coords(x, y);
                uudet.put(siirto, i+1);
            }
        }

        public int hashCode() {
            return Integer.parseInt(x + "0" + y);
        }
    }

    synchronized public static void main(String[] args) {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            koko = Integer.parseInt(br.readLine().trim());

        } catch (IOException ioe) {
            System.out.println(ioe);
        }

        lauta.put(new Coords(0, 0), 0);

        int kokoToiseen = koko * koko;
        while (lauta.size() < kokoToiseen) {
            //boolean loytyyko = false;

            uudet = new HashMap<>();

            for (Coords coord : lauta.keySet()) {

                if (lauta.get(coord) == i) {
                    //loytyyko = true;

                    coord.move(1, 2);
                    coord.move(-1, 2);
                    coord.move(1, -2);
                    coord.move(-1, -2);

                    coord.move(2, 1);
                    coord.move(-2, 1);
                    coord.move(2, -1);
                    coord.move(-2, -1);
                };

            }

            //if(!loytyyko) {
            //    break;
            //}

            for (Map.Entry<Coords, Integer>  entry : uudet.entrySet()) {
                lauta.putIfAbsent(entry.getKey(), entry.getValue());
            }

            i++;
        }

        for (int x = 0; x < koko; x++) {
            for (int y = 0; y < koko; y++) {
                if(y != 0) {
                    System.out.print(" ");
                }
                System.out.print(lauta.getOrDefault(new Coords(x, y), 0));
            }

            System.out.print("\n");
        }
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
4

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

user output
0 3 2 5
3 4 1 2
2 1 4 3
5 2 3 2

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
25

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

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

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
49

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

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

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
50

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

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

Test 11

Group: 3

Verdict: ACCEPTED

input
75

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

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

Test 12

Group: 3

Verdict: ACCEPTED

input
99

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

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

Test 13

Group: 3

Verdict: ACCEPTED

input
100

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

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