-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2916.cpp
70 lines (64 loc) · 1000 Bytes
/
2916.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
// 2916. 자와 각도기
// 2019.09.04
// 다이나믹 프로그래밍
#include<iostream>
#include<queue>
using namespace std;
int n, k;
int d[361];
int a[11];
int main()
{
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
queue<int> q;
q.push(0);
d[0] = 1;
while (!q.empty())
{
int x = q.front();
q.pop();
for (int i = 0; i < n; i++)
{
// 두 각을 더함
if (x + a[i] <= 360 && d[x + a[i]] == 0)
{
d[x + a[i]] = 1;
q.push(x + a[i]);
}
if (x + a[i] >= 360 && d[x + a[i] - 360] == 0)
{
d[x + a[i] - 360] = 1;
q.push(x + a[i] - 360);
}
// 두 각을 뺌
if (x - a[i] >= 0 && d[x - a[i]] == 0)
{
d[x - a[i]] = 1;
q.push(x - a[i]);
}
if (x - a[i] <= 0 && d[x - a[i] + 360] == 0)
{
d[x - a[i] + 360] = 1;
q.push(x - a[i] + 360);
}
}
}
for (int i = 0; i < k; i++)
{
int x;
cin >> x;
if (d[x])
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
return 0;
}