CSES - Putka Open 2015 – 1/6 - Results
Submission details
Task:Lähetit
Sender:
Submission time:2015-07-19 12:09:01 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.25 s1details
#20.21 s1details
#30.23 s1details
#40.21 s1details
#50.23 s1details
#6--2details
#7--2details
#81.05 s2details
#91.11 s2details
#101.05 s2details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details

Code

import java.util.Scanner;


public class Lahetit {
	
	public static int modulo = 1000000007;
	public static int lautaKoko;
	public static int lahetit;
	public static long lautojenLkm = 0;
    
    public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		lautaKoko = input.nextInt();
		lahetit = input.nextInt();
		kokeile();
		System.out.println(lautojenLkm);
    } 

    public static void kokeile() {
		for (int i = 0; i < lautaKoko; i++) {
			int[][] lauta = new int[lautaKoko][];
			lauta[0] = new int[lautaKoko];
			lauta[0][i] = 1;
			kokeile(lauta, 1, 0);
		}
		if (lahetit < lautaKoko) {
			int[][] lauta = new int[lautaKoko][];
			lauta[0] = new int[lautaKoko];
			kokeile(lauta, 1, 1);
		}
    }

    public static void kokeile(int[][] lauta, int rivi, int tyhjat) {
		if (rivi == lautaKoko) return;
//		tulostaLauta(lauta);
		if (rivi - tyhjat == lahetit) {
//			tulostaLauta(lauta);
			lautojenLkm += 1;
			lautojenLkm = lautojenLkm % modulo;
		}
		for (int i = 0; i < lautaKoko; i++) {
			if (voiAsettaa(lauta, rivi, i)) {
				lauta[rivi] = new int[lautaKoko];
				lauta[rivi][i] = 1;
				if (rivi == lautaKoko - 1) {
//					tulostaLauta(lauta);
					lautojenLkm += 1;
					lautojenLkm = lautojenLkm % modulo;
					continue;
				}
				kokeile(lauta, rivi+1, tyhjat);
			}
		}
		if (lahetit + tyhjat < lautaKoko) {
			lauta[rivi] = new int[lautaKoko];
			kokeile(lauta, rivi+1, tyhjat+1);
		}
    }
	
	public static boolean voiAsettaa(int[][] lauta, int rivi, int n) {
		int offset = 1;
        for (int i = rivi - 1; i >= 0; i--) {
            if (n-offset >= 0 && lauta[i][n-offset] == 1) return false;
			if (n+offset < lautaKoko && lauta[i][n+offset] == 1) return false;
			offset++;
        }
        return true;
	}
	
	public static void tulostaLauta(int[][] lauta) {
		for (int i = 0; i < lautaKoko; i++) {
			for (int j = 0; j < lautaKoko; j++) {
				try {
					System.out.print(lauta[i][j]);
				} catch (Exception e) {
				}
			}
			System.out.println("");
		}
		System.out.println("");
	}
	
}

Test details

Test 1

Group: 1

Verdict:

input
5 2

correct output
240

user output
1137

Test 2

Group: 1

Verdict:

input
5 4

correct output
2728

user output
626

Test 3

Group: 1

Verdict:

input
5 6

correct output
1960

user output
125

Test 4

Group: 1

Verdict:

input
5 8

correct output
32

user output
125

Test 5

Group: 1

Verdict:

input
5 10

correct output
0

user output
125

Test 6

Group: 2

Verdict:

input
10 4

correct output
1809464

user output
(empty)

Test 7

Group: 2

Verdict:

input
10 8

correct output
209594075

user output
(empty)

Test 8

Group: 2

Verdict:

input
10 12

correct output
811277399

user output
4834872

Test 9

Group: 2

Verdict:

input
10 16

correct output
17275136

user output
4834872

Test 10

Group: 2

Verdict:

input
10 20

correct output
0

user output
4834872

Test 11

Group: 3

Verdict:

input
100 40

correct output
126883191

user output
(empty)

Test 12

Group: 3

Verdict:

input
100 80

correct output
785497039

user output
(empty)

Test 13

Group: 3

Verdict:

input
100 120

correct output
324216296

user output
(empty)

Test 14

Group: 3

Verdict:

input
100 160

correct output
895190039

user output
(empty)

Test 15

Group: 3

Verdict:

input
100 200

correct output
0

user output
(empty)