mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-09 17:18:49 +00:00
D - Moves on Binary Tree
https://atcoder.jp/contests/abc243/submissions/30064173
This commit is contained in:
parent
573d0bffbd
commit
48722a9477
41
AtCoder/ABC243/D/D.cpp
Normal file
41
AtCoder/ABC243/D/D.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
std::vector<int> a;
|
||||
|
||||
int n, t;
|
||||
long long x;
|
||||
std::string s;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin >> n >> x >> s;
|
||||
std::reverse(s.begin(), s.end());
|
||||
for (char &c : s) {
|
||||
if (c == 'U') {
|
||||
t++;
|
||||
c = ' ';
|
||||
} else if (t) {
|
||||
t--;
|
||||
c = ' ';
|
||||
}
|
||||
}
|
||||
while (t--) x >>= 1;
|
||||
std::reverse(s.begin(), s.end());
|
||||
for (char c : s) {
|
||||
if (c == 'L') {
|
||||
x <<= 1;
|
||||
} else if (c == 'R') {
|
||||
x <<= 1;
|
||||
x |= 1;
|
||||
}
|
||||
}
|
||||
cout << x << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user