-
Notifications
You must be signed in to change notification settings - Fork 28
/
alicecub.cpp
95 lines (82 loc) · 2.3 KB
/
alicecub.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 1000000000
#define MAXN 1 << 16
using namespace std;
int a[MAXN];
int adjecency_matrix[16][16] =
{
{ 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
{ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0 },
{ 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 },
{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0 },
};
void preprocess_solution() {
a[(1<<8)-1] = 0;
queue<pair<int, int> > kju;
kju.push(make_pair((1<<8)-1, 0));
while (!kju.empty()) {
pair<int, int> par = kju.front(); kju.pop();
for (int i = 0; i < 16; ++i) {
int bit = (1<<(16-i-1));
if (bit & par.first) {
for (int j = 0; j < 16; ++j) {
if (adjecency_matrix[i][j]) {
int idx = (par.first & ~bit) | (1<<(16-j-1));
if (a[idx] == -1 && par.second < 3) {
a[idx] = par.second+1;
kju.push(make_pair(idx, par.second+1));
}
}
}
}
}
}
}
int main() {
int t;
scanf("%d", &t);
memset(a, -1, sizeof a);
preprocess_solution();
for (int qwertz = 0; qwertz < t; ++qwertz) {
int idx = 0;
for (int i = 0; i < 16; ++i) {
int x;
scanf("%d", &x);
if (x)
idx |= (1<<(16-i-1));
}
if (a[idx] == -1)
printf("Case #%d: more\n", qwertz+1);
else
printf("Case #%d: %d\n", qwertz+1, a[idx]);
}
return 0;
}