結果

問題 No.392 2分木をたどれ
ユーザー haruteruharuteru
提出日時 2016-07-25 12:03:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 54,772 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 08:53:03
合計ジャッジ時間 875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 10 ms
5,376 KB
testcase_02 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

#define MAX (4094)

int M;
int tree[MAX + 1];

void make_tree(int n, int m, int l)
{
    if (n >= MAX) {
        return;
    }
    int i = 0;
    for (; i < (1 << l); i++) {
        tree[n + i] = m + (i / 2);
    }
    make_tree(n + i, n, l + 1);
}

void solve(int n)
{
    char ans[256];
    int num = 0;
    while (n > 0) {
        if (n % 2) {
            ans[num++] = 'L';
        }
        else {
            ans[num++] = 'R';
        }
        n = tree[n];
    }
    for (; num > 0; num--) {
        cout << ans[num-1];
    }
    cout << endl;
}

int main()
{
    cin >> M;
    tree[0] = -1;
    make_tree(1, 0, 1);
    while (M--) {
        int a;
        cin >> a;
        solve(a);
    }
}
0