|
6 | 6 | #include <map>
|
7 | 7 | #include <cstring>
|
8 | 8 | #include <climits>
|
| 9 | +#define cmpl(A, X) for(int i = 1; i <= 9; i++) if(find((A).begin(), (A).end(), i) == (A).end()) (X).push_back(i); |
9 | 10 | using namespace std;
|
10 | 11 | typedef vector<int> vi;
|
11 | 12 | typedef vector<vi> vvi;
|
12 | 13 | typedef vector<string> vs;
|
13 | 14 | typedef vector<vs> vvs;
|
14 | 15 | typedef set<int> si;
|
15 | 16 | int maxv = 1000000;
|
| 17 | +int pd[4] = {0, 2, 4, 8}; |
| 18 | +int pp[4] = {1, 3, 5, 7}; |
| 19 | +vi v = {1,2,3,4,5,6,7,8,9}; |
16 | 20 |
|
17 | 21 | class Fifteen {
|
18 | 22 | public:
|
19 | 23 | //P plays maxv means P lose and win otherwise
|
20 |
| - int fp(si D, si P, si X){ |
21 |
| - int minv = maxv; |
22 |
| - for(int c : X) |
23 |
| - for(int a : P) |
24 |
| - for(int b : P) |
25 |
| - if(a != b && a+b+c == 15) minv = min(minv, c); |
26 |
| - if(X.size() == 1) return maxv; |
27 |
| - si XX = X; |
28 |
| - for(int c : X){ |
29 |
| - P.insert(c); |
30 |
| - XX.erase(c); |
31 |
| - if(fd(D, P, XX) == 0) minv = min(minv, c); |
32 |
| - P.erase(c); |
33 |
| - XX.insert(c); |
34 |
| - } |
35 |
| - if(minv != maxv) return minv; |
36 |
| - return maxv; |
37 |
| - } |
38 |
| - //D plays maxv means D wins and 0 means D lose |
39 |
| - int fd(si D, si P, si X){ |
40 |
| -// if(X.size() == 1) return maxv; |
41 |
| - for(int c : X) |
42 |
| - for(int a : D) |
43 |
| - for(int b : D) |
44 |
| - if(a != b && a+b+c == 15) return maxv; |
45 |
| - si XX = X; |
46 |
| - for(int c : X){ |
47 |
| - D.insert(c); |
48 |
| - XX.erase(c); |
49 |
| - if(fp(D, P, XX) == maxv) return maxv; |
50 |
| - D.erase(c); |
51 |
| - XX.insert(c); |
| 24 | + int f(vi A, int p){ |
| 25 | + vi M; |
| 26 | + for(int i = p; i < A.size(); i+=2) |
| 27 | + M.push_back(A[i]); |
| 28 | + sort(M.begin(), M.end()); |
| 29 | + for(int a : M) |
| 30 | + for(int b : M) |
| 31 | + for(int c : M) |
| 32 | + if(a != b && b != c && c != a && a+b+c == 15) return 1; |
| 33 | + int q = (p == 0 ? 1 : 0); |
| 34 | + if(A.size() == 9) return q; |
| 35 | + |
| 36 | + vi X, XX; |
| 37 | + cmpl(A, X); |
| 38 | + XX = A; |
| 39 | + for(int r : X){ |
| 40 | + XX.push_back(r); |
| 41 | + if(f(XX, q)) return 0; |
| 42 | + XX.pop_back(); |
52 | 43 | }
|
53 |
| - return 0; |
| 44 | + |
| 45 | + return 1; |
54 | 46 | }
|
55 | 47 |
|
56 | 48 | string outcome(vector <int> moves)
|
57 | 49 | {
|
58 |
| - si D, P; |
59 |
| - vi v = {1,2,3,4,5,6,7,8,9}; |
60 |
| - si X(v.begin(), v.end()); |
61 |
| - for(int i = 0; i < moves.size(); i++){ |
62 |
| - int k = moves[i]; |
63 |
| - X.erase(k); |
64 |
| - if(i%2) P.insert(k); |
65 |
| - else D.insert(k); |
| 50 | + vi X; |
| 51 | + cmpl(moves, X); |
| 52 | + vi XX = moves; |
| 53 | + for(int r : X){ |
| 54 | + XX.push_back(r); |
| 55 | + if(f(XX, 1)) return "WIN "+to_string(r); |
| 56 | + XX.pop_back(); |
66 | 57 | }
|
67 |
| - int r = fp(D, P, X); |
68 |
| - if(r == maxv) return "LOSE"; |
69 |
| - return "WIN "+to_string(r); |
| 58 | + return "LOSE"; |
70 | 59 | }
|
71 | 60 |
|
72 | 61 | // BEGIN CUT HERE
|
|
0 commit comments