Submission #30087325
Source Code Expand
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
// using P = pair<ll,ll>;
using P = pair<int,int>;
using vint = vector<int>;
using vll = vector<ll>;
using vvint = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// const ll INF = (ll)2e18+9;
const int INF = (int)2e9+7;
// const ll MOD = (ll)1e9+9;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }
template<typename T>
void print(vector<T> v) {
int n = v.size();
rep(i,n) {
if (i == 0) cout << v[i];
else cout << ' ' << v[i];
}
cout << endl;
}
void solve() {
ll n, x;
cin >> n >> x;
string s;
cin >> s;
string mv = "";
rep(i,n) {
if (mv.size() != 0 && mv.back() != 'U' && s[i] == 'U') mv.pop_back();
else mv.push_back(s[i]);
}
ll ans = x;
for (char c : mv) {
if (c == 'U') ans /= 2;
if (c == 'L') ans *= 2;
if (c == 'R') ans = ans * 2 + 1;
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Moves on Binary Tree |
| User | goropikari |
| Language | C++ (GCC 9.2.1) |
| Score | 400 |
| Code Size | 1439 Byte |
| Status | AC |
| Exec Time | 34 ms |
| Memory | 5728 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| random_01.txt | AC | 34 ms | 5252 KiB |
| random_02.txt | AC | 14 ms | 3824 KiB |
| random_03.txt | AC | 33 ms | 5116 KiB |
| random_04.txt | AC | 13 ms | 3828 KiB |
| random_05.txt | AC | 28 ms | 5116 KiB |
| random_06.txt | AC | 18 ms | 4184 KiB |
| random_07.txt | AC | 32 ms | 5148 KiB |
| random_08.txt | AC | 34 ms | 4132 KiB |
| random_09.txt | AC | 29 ms | 5236 KiB |
| random_10.txt | AC | 18 ms | 4128 KiB |
| random_11.txt | AC | 33 ms | 5200 KiB |
| random_12.txt | AC | 24 ms | 4220 KiB |
| random_13.txt | AC | 23 ms | 5632 KiB |
| random_14.txt | AC | 22 ms | 5644 KiB |
| random_15.txt | AC | 26 ms | 5712 KiB |
| random_16.txt | AC | 30 ms | 5728 KiB |
| random_17.txt | AC | 29 ms | 5724 KiB |
| random_18.txt | AC | 26 ms | 5712 KiB |
| random_19.txt | AC | 26 ms | 5688 KiB |
| random_20.txt | AC | 23 ms | 5256 KiB |
| random_21.txt | AC | 23 ms | 5252 KiB |
| random_22.txt | AC | 31 ms | 5176 KiB |
| random_23.txt | AC | 28 ms | 5628 KiB |
| random_24.txt | AC | 23 ms | 5720 KiB |
| sample_01.txt | AC | 2 ms | 3516 KiB |
| sample_02.txt | AC | 2 ms | 3528 KiB |
| sample_03.txt | AC | 2 ms | 3564 KiB |