-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1941d.cpp
More file actions
62 lines (55 loc) · 1.47 KB
/
1941d.cpp
File metadata and controls
62 lines (55 loc) · 1.47 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
#include <bits/stdc++.h>
using namespace std;
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
#define F first
#define S second
#define pb push_back
#define cases int _; cin >> _; while(_--)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef set<int> si;
void solve() {
int n, m, x;
cin >> n >> m >> x;
vector<int> nodes = {x - 1};
for(int i = 0; i < m; i++) {
int dist; char c;
cin >> dist >> c;
set<int> new_nodes;
if(c == '?') {
for(auto j : nodes) {
int clockwise = (j + dist) % n;
int counter_clockwise = (j - dist + n) % n;
new_nodes.insert(clockwise);
new_nodes.insert(counter_clockwise);
}
} else if(c == '0') {
for(auto j : nodes) {
int clockwise = (j + dist) % n;
new_nodes.insert(clockwise);
}
} else {
for(auto j : nodes) {
int counter_clockwise = (j - dist + n) % n;
new_nodes.insert(counter_clockwise);
}
}
nodes.assign(new_nodes.begin(), new_nodes.end());
}
set<int> result;
for(auto node : nodes) {
result.insert(node + 1);
}
cout << result.size() << '\n';
for(auto node : result) {
cout << node << ' ';
}
cout << '\n';
}
int main() {
cases solve();
return 0;
}