CSES - Putka Open 2015 – 6/6 - Results
Submission details
Task:Shakki
Sender:
Submission time:2015-12-06 22:52:24 +0200
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
Test results
testverdicttimegroup
#10.26 s1details
#20.23 s1details
#30.24 s1details
#40.28 s1details
#50.23 s1details
#60.23 s1details
#70.23 s1details
#80.25 s1details
#90.23 s1details
#100.28 s1details
#110.25 s2details
#120.34 s2details
#130.32 s2details
#140.34 s2details
#150.23 s2details
#160.25 s2details
#170.41 s2details
#180.26 s2details
#190.26 s2details
#200.26 s2details
#210.21 s3details
#220.46 s3details
#230.35 s3details
#240.26 s3details
#250.33 s3details
#260.25 s3details
#270.34 s3details
#280.26 s3details
#290.25 s3details
#300.25 s3details
#310.40 s4details
#320.21 s4details
#330.34 s4details
#340.22 s4details
#350.26 s4details
#360.27 s4details
#370.25 s4details
#380.34 s4details
#390.24 s4details
#400.23 s4details

Code

//package shakki;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeSet;

/**
 *
 * @author Adreno
 */
public class Shakki {

    public static boolean[][] t;
    
    
    public static void main(String[] args) {
        boolean debug = false;
        //boolean debug = true;
        Scanner s = new Scanner(System.in);
        t = new boolean[8][8];
        //TreeSet<Ruutu> collisions = new TreeSet<>();
        //int[][] collisions = new int[8][8];
        for (int i=0; i<8; i++) {
            String line = s.next();
            for (int j=0; j<8; j++) {
                if (line.charAt(j) == 'M') t[i][j] = true;
                if (j>0) {
                    if (line.charAt(j) == line.charAt(j-1)) {
                        //col.add(new Collision(i,j-1, i,j));
                    }
                }
            }
        }
        for (int x=0; x<8; x++) {
            for (int y=1; y<8; y++) {
                if (t[y-1][x] == t[y][x]) {
                    //col.add(new Collision(y-1,x, y,x));
                }
            }
        }
        int score = score();
        
        Random rng = new Random();
        ArrayList<String> siirrot = new ArrayList<>();
        while (score > 0) {
            //int index = rng.nextInt(siirrot.size());
            int y = rng.nextInt(7);
            int x = rng.nextInt(7);
            kaanna(y,x);
            int newScore = score();
            if (newScore > score && rng.nextInt(100) >= 1) {
                peruKaanto(y,x);
            } else {
                score = newScore;
                siirrot.add(y + " " + x);
            }
            //System.out.println("score="+score);
        }
        System.out.println(siirrot.size());
        if (!debug) {
            for (String siirto : siirrot) System.out.println(siirto);
        }
    }
    
    public static void kaanna(int y, int x) {
        boolean vasenYla = t[y][x];
        boolean oikeaYla = t[y][x+1];
        boolean vasenAla = t[y+1][x];
        boolean oikeaAla = t[y+1][x+1];
        t[y][x] = vasenAla;
        t[y][x+1] = vasenYla;
        t[y+1][x+1] = oikeaYla;
        t[y+1][x] = oikeaAla;        
    }
    public static void peruKaanto(int y, int x) {
        boolean vasenYla = t[y][x];
        boolean oikeaYla = t[y][x+1];
        boolean vasenAla = t[y+1][x];
        boolean oikeaAla = t[y+1][x+1];
        t[y][x] = oikeaYla;
        t[y][x+1] = oikeaAla;
        t[y+1][x+1] = vasenAla;
        t[y+1][x] = vasenYla;        
    }
    
    public static int score() {
        int count = 0;
        for (int y=1; y<8; y++) {
            for (int x=1; x<8; x++) {
                if (t[y][x] == t[y-1][x]) count++;
                if (t[y][x] == t[y][x-1]) count++;
            }
        }
        for (int x=1; x<8; x++) {
            if (t[0][x] == t[0][x-1]) count++;
        }
        for (int y=1; y<8; y++) {
            if (t[y][0] == t[y-1][0]) count++;
        }
        return count;
    }
    
    public static int scoreAndSaveCollisionSpots() {
        int count = 0;
        for (int y=1; y<8; y++) {
            for (int x=1; x<8; x++) {
                if (t[y][x] == t[y-1][x]) count++;
                if (t[y][x] == t[y][x-1]) count++;
            }
        }
        for (int x=1; x<8; x++) {
            if (t[0][x] == t[0][x-1]) count++;
        }
        for (int y=1; y<8; y++) {
            if (t[y][0] == t[y-1][0]) count++;
        }
        return count;
    }
    
}

//class CollisionDB {
//    public TreeSet<Ruutu> db;
//
//    public CollisionDB() {
//        this.db = new TreeSet<>();
//    }
//    
//    public addCollision(int y, int x) {
//        Ruutu r = new Ruutu(y, x);
//        Ruutu
//    }
//    
//}

class Ruutu implements Comparable<Ruutu> {
    public int y;
    public int x;
    public int count;

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

    @Override
    public int compareTo(Ruutu o) {
        if (o.y != this.y) return this.y - o.y;
        return (this.x - o.x);
    }
    
    
}

class Collision {
    public int y1;
    public int x1;
    public int y2;
    public int x2;

    public Collision(int y1, int x1, int y2, int x2) {
        this.y1 = y1;
        this.x1 = x1;
        this.y2 = y2;
        this.x2 = x2;
    }
    
}

Test details

Test 1

Group: 1

Verdict:

input
VMMVVMVV
MMVVMVVV
MMVVMMMM
MVVVMVVM
MVVVVMVM
...

correct output
100000

user output
748
5 6
0 5
0 3
6 3
...

Test 2

Group: 1

Verdict:

input
MVMVVMMV
VVMMVVVV
VMMVMMVM
MVVVVMVM
MVMVMMVM
...

correct output
100000

user output
238
0 4
1 2
6 6
1 3
...

Test 3

Group: 1

Verdict:

input
VMMMVMVV
MMMVMVMV
VMMVMVVM
VVVMVMMV
MVMVMVMV
...

correct output
100000

user output
636
0 1
2 6
3 6
0 2
...

Test 4

Group: 1

Verdict:

input
VVVMVMVV
VMMVMVMM
MVVMMVMV
VMVMMVMM
MMVVMMVM
...

correct output
100000

user output
1909
2 6
4 0
5 3
6 4
...

Test 5

Group: 1

Verdict:

input
MVMVVMMM
VVMMVVMV
MVVMVVMM
VMVMVMMV
MMVMVVVM
...

correct output
100000

user output
481
5 4
4 3
2 1
1 4
...

Test 6

Group: 1

Verdict:

input
VMMVMVVM
VVMMVVMM
MMMVMVVM
VMMVMMVM
MVMVMMMV
...

correct output
100000

user output
313
4 3
6 4
3 6
5 3
...

Test 7

Group: 1

Verdict:

input
MVVVVMMM
MMMMMMMM
VVVVVMMV
MMVVMVVM
VMVVVVMV
...

correct output
100000

user output
606
0 0
1 4
0 1
3 0
...

Test 8

Group: 1

Verdict:

input
VMMVMVMM
MMMVVMMM
MVVVVVVV
VVVVMMMV
MVVVMVVM
...

correct output
100000

user output
859
2 4
4 2
6 1
1 6
...

Test 9

Group: 1

Verdict:

input
VVVVVMMM
MMVVVVVV
MVVVMMMM
VVMVVVVM
VMMVMVMM
...

correct output
100000

user output
478
0 6
4 1
3 1
5 6
...

Test 10

Group: 1

Verdict:

input
VMMVMMMM
VVMVVVVV
VMMVMVMV
VMMVMVMM
VVVMMMMM
...

correct output
100000

user output
2525
4 1
3 0
4 3
1 4
...

Test 11

Group: 2

Verdict:

input
VMVMVVMM
MMVMVVMM
VMVVVMMV
VVVMVMVM
VVMMVVMM
...

correct output
25000

user output
1302
5 5
0 6
6 5
1 2
...

Test 12

Group: 2

Verdict:

input
MVMVVMVV
VMMVVMVM
VMVVVMMM
VMMMMVVM
MMVVVMMM
...

correct output
25000

user output
4629
1 3
5 6
6 0
0 3
...

Test 13

Group: 2

Verdict:

input
MVVMMVVV
MMVVMVMM
VVVMVMVV
VMVMMMMM
MVVMMVMV
...

correct output
25000

user output
3927
1 1
3 3
4 2
5 5
...

Test 14

Group: 2

Verdict:

input
VVMMMVMV
VMVVVMVV
VVMVVVMM
MVVMVMVM
MMVVMMMM
...

correct output
25000

user output
4062
5 5
0 3
6 1
5 0
...

Test 15

Group: 2

Verdict:

input
MVVVMVVV
MMMMVMMM
MVMMMVVM
MMVVVMVM
VMVVVMMV
...

correct output
25000

user output
641
6 2
0 6
4 6
5 1
...

Test 16

Group: 2

Verdict:

input
VMMVMVVM
VMMVVVVV
MVMVMMVM
VMMVVVMV
VVMVMMVM
...

correct output
25000

user output
994
2 2
1 2
3 3
4 1
...

Test 17

Group: 2

Verdict:

input
MVVMMVVM
MVVVMMMV
MVVMMVVM
VMMVMVMV
VMMVMMMM
...

correct output
25000

user output
6618
0 0
1 4
4 1
6 6
...

Test 18

Group: 2

Verdict:

input
MVMMVVMM
VVMMMMVV
VMVVVVVM
MVMMMVMV
VMVVVMVM
...

correct output
25000

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

Test 19

Group: 2

Verdict:

input
MVVVVVVV
VMMVMVVM
VMVMMMMV
MVMVMMMM
MMVVVMMM
...

correct output
25000

user output
1714
4 6
3 5
5 4
6 2
...

Test 20

Group: 2

Verdict:

input
MVVVMMMM
MMVMMVMV
MVVVVVMM
VVMMMVVM
VVVMVMVV
...

correct output
25000

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

Test 21

Group: 3

Verdict:

input
VMVVMVMM
MMMMVMMV
VVVMVVVV
MVMVMVVM
VMMVMMMM
...

correct output
5000

user output
92
2 4
0 3
3 4
5 4
...

Test 22

Group: 3

Verdict:

input
VVVVVVMM
MMMVMMVV
VVVVVVMV
MMMVMVVV
MVVMMMMV
...

correct output
5000

user output
11431
3 0
0 6
0 5
5 6
...

Test 23

Group: 3

Verdict:

input
MMVMVMVV
MMVVMVVM
VMMVVMVM
MMMMMMVV
MVVVVMVM
...

correct output
5000

user output
5363
1 2
3 5
6 4
6 1
...

Test 24

Group: 3

Verdict:

input
MVMVVMVM
VVMVVMVM
MMMMVMVV
MVVMMVVV
MMMMMVVV
...

correct output
5000

user output
1705
5 0
3 3
3 5
3 3
...

Test 25

Group: 3

Verdict:

input
MVVVMVVM
MMMMVVMV
VMMVMMVV
VVMVMVMV
MVMMMVMM
...

correct output
5000

user output
4400
0 1
3 2
6 4
1 5
...

Test 26

Group: 3

Verdict:

input
VMVMVVVM
MMMVVVMM
MMVVVVVM
VVVVMMVV
VMMVVMMV
...

correct output
5000

user output
763
3 6
4 2
1 0
1 4
...

Test 27

Group: 3

Verdict:

input
MMVMMVVM
MVVVMVMV
MVVVMVVM
VMVMMMVV
VMMVVVVV
...

correct output
5000

user output
4838
2 5
4 5
6 0
6 3
...

Test 28

Group: 3

Verdict:

input
MVMMVMMV
VMVMMMVV
MMMMVVMV
VVVVMMMM
MMMVMMVV
...

correct output
5000

user output
1345
1 5
1 6
6 6
2 3
...

Test 29

Group: 3

Verdict:

input
VVVVMVMV
MMMVVMVM
MVVVMVMV
VVVMVVMM
VMMMMMVV
...

correct output
5000

user output
1331
2 1
6 6
0 0
3 1
...

Test 30

Group: 3

Verdict:

input
MVVVMVVV
MMVVMMMM
MVVVVVVV
MVMVMMMV
VMMMVMMM
...

correct output
5000

user output
613
0 4
3 0
4 5
4 5
...

Test 31

Group: 4

Verdict:

input
MVMMVMMV
VVVMMVVV
VMMVVMMV
VVMMMVVM
VVVMMMVV
...

correct output
250

user output
5753
5 1
0 6
2 6
1 1
...

Test 32

Group: 4

Verdict:

input
VVMMVVVM
VMVVMMVV
VMMMMMMV
VVMVMVVV
VMMVMVMM
...

correct output
250

user output
339
4 5
2 1
4 3
1 3
...

Test 33

Group: 4

Verdict:

input
MMVVMVMV
VVVMVMMM
VVVVMVMM
MVVMVVMV
VMMVMVVM
...

correct output
250

user output
5476
6 0
6 2
0 2
2 1
...

Test 34

Group: 4

Verdict:

input
VMVMVVMV
MVVMMMMM
MMVVMMMM
VMVMVVVM
VMMMVVVM
...

correct output
250

user output
281
4 3
3 2
1 3
2 6
...

Test 35

Group: 4

Verdict:

input
VMVMVMMM
VMMVVVMM
MMVMVMMM
MVMMVVVV
VMMVMMMV
...

correct output
250

user output
693
6 5
3 6
6 1
0 6
...

Test 36

Group: 4

Verdict:

input
MVMVMVMM
MVMVMMMV
MMVVVVMM
MVMVVVVV
VMMMVVMM
...

correct output
250

user output
2461
1 2
1 4
6 1
3 5
...

Test 37

Group: 4

Verdict:

input
VMMMMVMM
VVMMMVMV
VMVVVVVV
MVMMMVVM
VMVMMVVM
...

correct output
250

user output
1393
4 6
4 4
2 5
4 6
...

Test 38

Group: 4

Verdict:

input
VMMVMVMV
VVMVMVMM
MMMVMVMM
MVVVVMMM
MMVVVMVV
...

correct output
250

user output
4604
5 1
2 4
1 6
1 6
...

Test 39

Group: 4

Verdict:

input
MMMMMVMV
MVVMMMMV
VMVVVVMM
VMVVVMMV
MVMMMVMM
...

correct output
250

user output
511
2 2
3 6
3 4
1 3
...

Test 40

Group: 4

Verdict:

input
VMMMMMMV
VMMVVVVV
MVMMVMMV
MVVVVMMV
MVVVVMMM
...

correct output
250

user output
652
0 0
0 0
1 4
5 2
...