CSES - Putka Open 2015 – 6/6 - Results
Submission details
Task:Shakki
Sender:
Submission time:2015-12-04 21:33:18 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
Test results
testverdicttimegroup
#10.06 s1details
#20.06 s1details
#30.05 s1details
#40.05 s1details
#50.06 s1details
#60.05 s1details
#70.06 s1details
#80.06 s1details
#90.06 s1details
#100.04 s1details
#110.04 s2details
#120.05 s2details
#130.05 s2details
#140.06 s2details
#150.06 s2details
#160.05 s2details
#170.05 s2details
#180.06 s2details
#190.06 s2details
#200.05 s2details
#210.05 s3details
#220.05 s3details
#230.06 s3details
#240.05 s3details
#250.05 s3details
#260.05 s3details
#270.05 s3details
#280.06 s3details
#290.05 s3details
#300.05 s3details
#310.05 s4details
#320.06 s4details
#330.06 s4details
#340.06 s4details
#350.06 s4details
#36ACCEPTED0.06 s4details
#370.06 s4details
#380.07 s4details
#390.06 s4details
#400.05 s4details

Compiler report

input/code.cpp: In function 'unsigned int rot_4x4(unsigned int, int, int)':
input/code.cpp:13:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   auto n=b&~(0x33<<y*4+x);
                       ^
input/code.cpp:14:15: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   n|=(b&1<<y*4+x)<<1;
               ^
input/code.cpp:15:17: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   n|=(b&1<<y*4+x+1)<<4;
                 ^
input/code.cpp:16:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   n|=(b&1<<(y+1)*4+x)>>4;
                   ^
input/code.cpp:17:21: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   n|=(b&1<<(y+1)*4+x+1)>>1;
                     ^
input/code.cpp: In function 'void print_4x4(unsigned int)':
input/code.cpp:24:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
       std::cout<<".x"[b>>y*4+x&1];
                             ^
input/code.cpp: In f...

Code

#include <assert.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
const unsigned P16=1<<16;
unsigned depth_4x4[P16];
unsigned yx_4x4[P16];
unsigned rot_4x4(unsigned b,int x,int y){
auto n=b&~(0x33<<y*4+x);
n|=(b&1<<y*4+x)<<1;
n|=(b&1<<y*4+x+1)<<4;
n|=(b&1<<(y+1)*4+x)>>4;
n|=(b&1<<(y+1)*4+x+1)>>1;
return n;
}
void print_4x4(unsigned b){
for(int y=0;y<4;++y,std::cout<<'\n')
for(int x=0;x<4;++x)
std::cout<<".x"[b>>y*4+x&1];
}
std::vector<int> get_counts(const std::vector<std::string>&M){
std::vector<int>counts(4);
for(int y=0;y<8;++y){
for(int x=0;x<8;++x){
if(M[y][x]=='M')++counts[y/4*2+x/4];
}
}
return counts;
}
int balance(const std::vector<int>&counts){
int b=0;
for(int c:counts)b+=abs(c-8);
return b;
}
void rot(std::vector<std::string>&M,int x,int y){
std::swap(M[y][x],M[y][x+1]);
std::swap(M[y+1][x],M[y][x]);
std::swap(M[y+1][x+1],M[y+1][x]);
}
std::vector<int> solve(std::vector<std::string>M){
std::vector<int>solution;
for(;;){
auto cs=get_counts(M);
if(cs[0]==8&&cs[1]==8&&cs[2]==8)break;
for(int y=0;y<7;++y){
for(int x=0;x<7;++x){
rot(M,x,y);
auto cs2=get_counts(M);
if(balance(cs2)<balance(cs)){
solution.push_back(y*8+x);
goto next;
}
}
}
{
int x=::rand()%7;
int y=::rand()%7;
rot(M,x,y);
solution.push_back(y*8+x);
}
next:;
}
for(int Y=0;Y<2;++Y)for(int X=0;X<2;++X){
auto block=0u;
for(int y=0;y<4;++y)for(int x=0;x<4;++x)
if(M[Y*4+y][X*4+x]=='M')
block|=1<<y*4+x;
while(depth_4x4[block]){
auto yx=yx_4x4[block];
auto y=yx/4+Y*4;
auto x=yx%4+X*4;
solution.push_back(y*8+x);
block=rot_4x4(block,yx%4,yx/4);
}
}
return solution;
}
int main(){
for(int i=0;i<P16;++i)depth_4x4[i]=999999;
unsigned solved=0x5A5A;
depth_4x4[solved]=0;
for(unsigned depth=1;;++depth){
std::unordered_set<unsigned>prev;
for(int i=0;i<P16;++i)if(depth_4x4[i]==depth-1)prev.insert(i);
if(prev.empty())break;
for(auto p:prev)for(int y=0;y<3;++y)for(int x=0;x<3;++x){
auto n=rot_4x4(p,x,y);
n=rot_4x4(n,x,y);
n=rot_4x4(n,x,y);
assert(__builtin_popcount(n) == 8);
if(depth_4x4[n]>depth){
depth_4x4[n]=depth;
yx_4x4[n]=y*4+x;
}
}
}
/*
std::vector<int>counts;
for(int i=0;i<P16;++i){
if(depth_4x4[i]>1000)continue;
while(counts.size()<=depth_4x4[i])counts.push_back(0);
++counts[depth_4x4[i]];
}
for(int i=0;i<counts.size();++i)
std::cout<<i<<' '<<counts[i]<<'\n';
*/
std::vector<std::string>M(8);
for(auto&s:M)std::cin>>s;
auto solution=solve(M);
for(auto&s:M)for(auto&c:s)c="MV"[c=='M'];
auto solution2=solve(M);
if(solution2.size()<solution.size())solution=std::move(solution2);
std::cout<<solution.size()<<'\n';
for(int yx:solution)std::cout<<yx%8+1<<' '<<yx/8+1<<'\n';
}

Test details

Test 1

Group: 1

Verdict:

input
VMMVVMVV
MMVVMVVV
MMVVMMMM
MVVVMVVM
MVVVVMVM
...

correct output
100000

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

Test 2

Group: 1

Verdict:

input
MVMVVMMV
VVMMVVVV
VMMVMMVM
MVVVVMVM
MVMVMMVM
...

correct output
100000

user output
29
1 4
3 6
1 4
4 4
...

Test 3

Group: 1

Verdict:

input
VMMMVMVV
MMMVMVMV
VMMVMVVM
VVVMVMMV
MVMVMVMV
...

correct output
100000

user output
29
7 5
4 1
7 1
4 2
...

Test 4

Group: 1

Verdict:

input
VVVMVMVV
VMMVMVMM
MVVMMVMV
VMVMMVMM
MMVVMMVM
...

correct output
100000

user output
34
4 1
4 7
2 5
3 6
...

Test 5

Group: 1

Verdict:

input
MVMVVMMM
VVMMVVMV
MVVMVVMM
VMVMVMMV
MMVMVVVM
...

correct output
100000

user output
32
2 4
1 4
1 4
4 6
...

Test 6

Group: 1

Verdict:

input
VMMVMVVM
VVMMVVMM
MMMVMVVM
VMMVMMVM
MVMVMMMV
...

correct output
100000

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

Test 7

Group: 1

Verdict:

input
MVVVVMMM
MMMMMMMM
VVVVVMMV
MMVVMVVM
VMVVVVMV
...

correct output
100000

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

Test 8

Group: 1

Verdict:

input
VMMVMVMM
MMMVVMMM
MVVVVVVV
VVVVMMMV
MVVVMVVM
...

correct output
100000

user output
25
1 4
3 6
4 3
4 6
...

Test 9

Group: 1

Verdict:

input
VVVVVMMM
MMVVVVVV
MVVVMMMM
VVMVVVVM
VMMVMVMM
...

correct output
100000

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

Test 10

Group: 1

Verdict:

input
VMMVMMMM
VVMVVVVV
VMMVMVMV
VMMVMVMM
VVVMMMMM
...

correct output
100000

user output
24
4 2
1 3
3 1
2 2
...

Test 11

Group: 2

Verdict:

input
VMVMVVMM
MMVMVVMM
VMVVVMMV
VVVMVMVM
VVMMVVMM
...

correct output
25000

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

Test 12

Group: 2

Verdict:

input
MVMVVMVV
VMMVVMVM
VMVVVMMM
VMMMMVVM
MMVVVMMM
...

correct output
25000

user output
30
3 6
4 1
4 2
4 7
...

Test 13

Group: 2

Verdict:

input
MVVMMVVV
MMVVMVMM
VVVMVMVV
VMVMMMMM
MVVMMVMV
...

correct output
25000

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

Test 14

Group: 2

Verdict:

input
VVMMMVMV
VMVVVMVV
VVMVVVMM
MVVMVMVM
MMVVMMMM
...

correct output
25000

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

Test 15

Group: 2

Verdict:

input
MVVVMVVV
MMMMVMMM
MVMMMVVM
MMVVVMVM
VMVVVMMV
...

correct output
25000

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

Test 16

Group: 2

Verdict:

input
VMMVMVVM
VMMVVVVV
MVMVMMVM
VMMVVVMV
VVMVMMVM
...

correct output
25000

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

Test 17

Group: 2

Verdict:

input
MVVMMVVM
MVVVMMMV
MVVMMVVM
VMMVMVMV
VMMVMMMM
...

correct output
25000

user output
24
4 2
3 2
2 3
1 2
...

Test 18

Group: 2

Verdict:

input
MVMMVVMM
VVMMMMVV
VMVVVVVM
MVMMMVMV
VMVVVMVM
...

correct output
25000

user output
36
3 3
4 1
1 4
6 3
...

Test 19

Group: 2

Verdict:

input
MVVVVVVV
VMMVMVVM
VMVMMMMV
MVMVMMMM
MMVVVMMM
...

correct output
25000

user output
53
4 6
5 6
4 6
4 2
...

Test 20

Group: 2

Verdict:

input
MVVVMMMM
MMVMMVMV
MVVVVVMM
VVMMMVVM
VVVMVMVV
...

correct output
25000

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

Test 21

Group: 3

Verdict:

input
VMVVMVMM
MMMMVMMV
VVVMVVVV
MVMVMVVM
VMMVMMMM
...

correct output
5000

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

Test 22

Group: 3

Verdict:

input
VVVVVVMM
MMMVMMVV
VVVVVVMV
MMMVMVVV
MVVMMMMV
...

correct output
5000

user output
38
2 4
3 3
1 4
4 1
...

Test 23

Group: 3

Verdict:

input
MMVMVMVV
MMVVMVVM
VMMVVMVM
MMMMMMVV
MVVVVMVM
...

correct output
5000

user output
34
4 2
4 2
3 3
4 2
...

Test 24

Group: 3

Verdict:

input
MVMVVMVM
VVMVVMVM
MMMMVMVV
MVVMMVVV
MMMMMVVV
...

correct output
5000

user output
59
4 1
1 4
2 5
4 1
...

Test 25

Group: 3

Verdict:

input
MVVVMVVM
MMMMVVMV
VMMVMMVV
VVMVMVMV
MVMMMVMM
...

correct output
5000

user output
21
2 4
3 1
2 3
2 2
...

Test 26

Group: 3

Verdict:

input
VMVMVVVM
MMMVVVMM
MMVVVVVM
VVVVMMVV
VMMVVMMV
...

correct output
5000

user output
37
7 1
4 4
4 2
3 3
...

Test 27

Group: 3

Verdict:

input
MMVMMVVM
MVVVMVMV
MVVVMVVM
VMVMMMVV
VMMVVVVV
...

correct output
5000

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

Test 28

Group: 3

Verdict:

input
MVMMVMMV
VMVMMMVV
MMMMVVMV
VVVVMMMM
MMMVMMVV
...

correct output
5000

user output
53
7 4
2 4
7 3
3 2
...

Test 29

Group: 3

Verdict:

input
VVVVMVMV
MMMVVMVM
MVVVMVMV
VVVMVVMM
VMMMMMVV
...

correct output
5000

user output
31
6 1
7 4
4 2
4 2
...

Test 30

Group: 3

Verdict:

input
MVVVMVVV
MMVVMMMM
MVVVVVVV
MVMVMMMV
VMMMVMMM
...

correct output
5000

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

Test 31

Group: 4

Verdict:

input
MVMMVMMV
VVVMMVVV
VMMVVMMV
VVMMMVVM
VVVMMMVV
...

correct output
250

user output
29
4 4
2 2
5 4
1 4
...

Test 32

Group: 4

Verdict:

input
VVMMVVVM
VMVVMMVV
VMMMMMMV
VVMVMVVV
VMMVMVMM
...

correct output
250

user output
39
3 3
4 1
6 3
3 6
...

Test 33

Group: 4

Verdict:

input
MMVVMVMV
VVVMVMMM
VVVVMVMM
MVVMVVMV
VMMVMVVM
...

correct output
250

user output
40
4 4
4 1
4 1
6 4
...

Test 34

Group: 4

Verdict:

input
VMVMVVMV
MVVMMMMM
MMVVMMMM
VMVMVVVM
VMMMVVVM
...

correct output
250

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

Test 35

Group: 4

Verdict:

input
VMVMVMMM
VMMVVVMM
MMVMVMMM
MVMMVVVV
VMMVMMMV
...

correct output
250

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

Test 36

Group: 4

Verdict: ACCEPTED

input
MVMVMVMM
MVMVMMMV
MMVVVVMM
MVMVVVVV
VMMMVVMM
...

correct output
250

user output
23
1 1
3 1
3 1
1 1
...

Test 37

Group: 4

Verdict:

input
VMMMMVMM
VVMMMVMV
VMVVVVVV
MVMMMVVM
VMVMMVVM
...

correct output
250

user output
28
4 3
4 2
2 4
4 1
...

Test 38

Group: 4

Verdict:

input
VMMVMVMV
VVMVMVMM
MMMVMVMM
MVVVVMMM
MMVVVMVV
...

correct output
250

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

Test 39

Group: 4

Verdict:

input
MMMMMVMV
MVVMMMMV
VMVVVVMM
VMVVVMMV
MVMMMVMM
...

correct output
250

user output
37
2 5
4 3
2 4
2 4
...

Test 40

Group: 4

Verdict:

input
VMMMMMMV
VMMVVVVV
MVMMVMMV
MVVVVMMV
MVVVVMMM
...

correct output
250

user output
36
4 2
7 1
4 6
4 2
...