-
Notifications
You must be signed in to change notification settings - Fork 0
/
28706.cpp
78 lines (73 loc) · 1.81 KB
/
28706.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
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
vector<pair<pair<char, int>,pair<char, int>>>v;
void solving (int num, int turn);
int n;
bool isTrue = 0;
bool visited[200001][10] = {0, };
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
for(int i = 0; i < 200001; i++){
for(int j = 0; j < 10; j++){
visited[i][j] = 0;
}
}
v.clear();
isTrue = 0;
int tmp1, tmp2;
char a, b;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a;
cin >> tmp1;
cin >> b;
cin >> tmp2;
v.push_back(make_pair(make_pair(a, tmp1), make_pair(b, tmp2)));
}
solving(1, 0);
if(isTrue) cout << "LUCKY" << '\n';
else cout << "UNLUCKY" << '\n';
}
}
void solving(int num, int turn){
if(turn == n){
if(num%7 == 0) isTrue = 1;
return;
}
if(v[turn].first.first == '*'){
int tmp = (num*((v[turn].first.second)%7))%7;
if(visited[turn][tmp] == 0){
visited[turn][tmp] = 1;
solving(tmp, turn+1);
}
}
else {
int tmp = (num+((v[turn].first.second)%7))%7;
if(visited[turn][tmp] == 0){
visited[turn][tmp] = 1;
solving(tmp, turn+1);
}
}
if(v[turn].second.first == '*'){
int tmp = (num*((v[turn].second.second)%7))%7;
if(visited[turn][tmp] == 0){
visited[turn][tmp] = 1;
solving(tmp, turn+1);
}
}
else {
int tmp = (num+((v[turn].second.second)%7))%7;
if(visited[turn][tmp] == 0){
visited[turn][tmp] = 1;
solving(tmp, turn+1);
}
}
}