結果
問題 | No.392 2分木をたどれ |
ユーザー |
![]() |
提出日時 | 2016-12-29 10:57:20 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1,085 ms / 2,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 375 ms |
コンパイル使用メモリ | 24,832 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 03:14:34 |
合計ジャッジ時間 | 2,955 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:28:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d", &m); | ^~~~~~~~~~~~~~~ main.c:32:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d", &a); | ^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>#include <math.h>#define rep(i, n) for (i = 0; i < n; i++)#define left 0#define right 1int follow(int s, int r) {int i, a = s;if (r == left) a = 2 * a + 1;else if (r == right) a = 2 * a + 2;return a;}int getbit(int x, int n) {return !!(x & (int)pow(2, n - 1));}int depth(int n) {int i, t = 0;rep(i, 12) {t += pow(2, i);if (t > n) return i;}}int main() {int m;scanf("%d", &m);int a, i, j, k;rep(i, m) {scanf("%d", &a);int d = depth(a);rep(j, pow(2, d)) {int t = 0, ans[11];rep(k, d) {ans[k] = getbit(j, k + 1);t = follow(t, ans[k]);}if (t == a) {rep(k, d) putchar(ans[k] == left ? 'L' : 'R');printf("\n");break;}}}return 0;}