-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjongman_1_9.19.cpp
More file actions
72 lines (72 loc) · 1.48 KB
/
jongman_1_9.19.cpp
File metadata and controls
72 lines (72 loc) · 1.48 KB
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
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
short cache[1<<25];
short win(int bits){
short& ret = cache[bits];
if(ret!=-1) return ret;
ret = 0;
for(int i=0;i<25;++i){
if(bits & 1<<i){
bits ^= 1<<i;
if(i+1<25 && i%5!=4 && bits & 1<<i+1){
bits ^= 1<<i+1;
if(!win(bits)) return ret = 1;
if(i-5>=0 && i/5!=0 && bits & 1<<i-5){
bits ^= 1<<i-5;
if(!win(bits)) return ret = 1;
bits |= 1<<i-5;
}
if(i+5<25 && i/5!=4 && bits & 1<<i+5){
bits ^= 1<<i+5;
if(!win(bits)) return ret = 1;
bits |= 1<<i+5;
}
bits |= 1<<i+1;
}
if(i+5<25 && i/5!=4 && bits & 1<<i+5){
bits ^= 1<<i+5;
if(!win(bits)) return ret = 1;
if(i-1>=0 && i%5!=0 && bits & 1<<i-1){
bits ^= 1<<i-1;
if(!win(bits)) return ret = 1;
bits |= 1<<i-1;
}
bits |= 1<<i+5;
}
if(i-1>=0 && i%5!=0 && bits & 1<<i-1){
bits ^= 1<<i-1;
if(i-5>=0 && i/5!=0 && bits & 1<<i-5){
bits ^= 1<<i-5;
if(!win(bits)) return ret = 1;
bits |= 1<<i-5;
}
bits |= 1<<i-1;
}
bits |= 1<<i;
}
}
return ret;
}
int main(){
int C;
cin >> C;
memset(cache,-1,sizeof(cache));
for(int test=0;test<C;++test){
int initial = 0;
for(int i=0;i<5;++i){
string str;
cin >> str;
for(int j=0;j<5;++j){
if(str[j]=='.') initial |= 1<<i*5+j;
}
}
if(win(initial)==1) cout << "WINNING" << endl;
else cout << "LOSING" << endl;
}
return 0;
}