Submission #30084645


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;
}

string to_bin(ll n) {
    string s = "";
    while (n) {
        s.push_back('0' + (n % 2));
        n /= 2;
    }
    reverse(all(s));

    return s;
}

ll to_num(string s) {
    reverse(all(s));
    ll ans = 0;
    rep(i,s.size()) {
        ans += ll(s[i] - '0') << i;
    }

    return ans;
}

void solve() {
    ll n, x;
    cin >> n >> x;
    string s;
    cin >> s;

    string num = to_bin(x);

    for (char c : s) {
        if (c == 'U') num.pop_back();
        if (c == 'L') num.push_back('0');
        if (c == 'R') num.push_back('1');
    }

    cout << to_num(num) << 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 1638 Byte
Status AC
Exec Time 36 ms
Memory 5776 KiB

Compile Error

./Main.cpp: In function ‘ll to_num(std::string)’:
./Main.cpp:8:36: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    8 | #define rep(i,n) for (int i = 0; i < (n); ++i)
      |                                    ^
./Main.cpp:51:5: note: in expansion of macro ‘rep’
   51 |     rep(i,s.size()) {
      |     ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 27
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 35 ms 5180 KiB
random_02.txt AC 15 ms 3752 KiB
random_03.txt AC 31 ms 5124 KiB
random_04.txt AC 13 ms 3876 KiB
random_05.txt AC 35 ms 5236 KiB
random_06.txt AC 19 ms 4092 KiB
random_07.txt AC 36 ms 5124 KiB
random_08.txt AC 29 ms 4160 KiB
random_09.txt AC 32 ms 5224 KiB
random_10.txt AC 17 ms 4052 KiB
random_11.txt AC 33 ms 5224 KiB
random_12.txt AC 27 ms 4088 KiB
random_13.txt AC 31 ms 5708 KiB
random_14.txt AC 28 ms 5772 KiB
random_15.txt AC 30 ms 5648 KiB
random_16.txt AC 29 ms 5616 KiB
random_17.txt AC 30 ms 5776 KiB
random_18.txt AC 26 ms 5592 KiB
random_19.txt AC 28 ms 5604 KiB
random_20.txt AC 30 ms 5100 KiB
random_21.txt AC 29 ms 5172 KiB
random_22.txt AC 30 ms 5184 KiB
random_23.txt AC 30 ms 5604 KiB
random_24.txt AC 28 ms 5652 KiB
sample_01.txt AC 2 ms 3500 KiB
sample_02.txt AC 2 ms 3564 KiB
sample_03.txt AC 3 ms 3548 KiB