-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#269.cpp
More file actions
37 lines (32 loc) · 745 Bytes
/
#269.cpp
File metadata and controls
37 lines (32 loc) · 745 Bytes
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
#include<iostream>
#include<unordered_set>
#include<string>
using namespace std;
string dominoes(string s) {
unordered_set<int> pivots;
for (int i = 0; i < s.length(); ++i) {
if (s[i] != '.') pivots.insert(i);
}
while (!pivots.empty()) {
unordered_set<int> tmp;
for (const int &i : pivots) {
int nextIndex = (s[i] == 'R' ? i + 1 : i - 1);
if (nextIndex >= 0 && nextIndex < s.length() && pivots.find(nextIndex) == pivots.end()) {
if (s[nextIndex] == '.') {
s[nextIndex] = s[i];
tmp.insert(nextIndex);
} else if (s[nextIndex] != s[i]) {
s[nextIndex] = '.';
tmp.erase(nextIndex);
}
}
}
pivots = tmp;
}
return s;
}
int main() {
string inp;
cin >> inp;
cout << dominoes(inp) << endl;
}