結果
| 問題 |
No.392 2分木をたどれ
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-07-16 05:27:11 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 2,724 bytes |
| コンパイル時間 | 881 ms |
| コンパイル使用メモリ | 116,140 KB |
| 実行使用メモリ | 19,456 KB |
| 最終ジャッジ日時 | 2024-10-15 12:59:55 |
| 合計ジャッジ時間 | 1,405 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
this.SetTree();
int queryCount = int.Parse(Reader.ReadLine());
for(int i=0; i<queryCount; i++) {
int idx = int.Parse(Reader.ReadLine());
Console.WriteLine(this.GetAns(idx));
}
}
private String GetAns(int idx) {
TreeNode current = this.NodeList[idx];
if(current.Parent == null) {
return string.Empty;
}
TreeNode parent = current.Parent;
if(parent.Left.ID == idx) {
return this.GetAns(parent.ID) + "L";
} else {
return this.GetAns(parent.ID) + "R";
}
}
private void SetTree() {
int max = 4094;
this.NodeList = new TreeNode[max+1];
int idx = 1;
Queue<int> q = new Queue<int>();
this.Root = new TreeNode(0);
this.NodeList[0] = this.Root;
q.Enqueue(0);
while (q.Count > 0)
{
int next = q.Dequeue();
this.NodeList[idx] = this.NodeList[next].AddChild(new TreeNode(idx));
q.Enqueue(idx);
idx++;
if(idx > max) {
break;
}
this.NodeList[idx] = this.NodeList[next].AddChild(new TreeNode(idx));
q.Enqueue(idx);
idx++;
if(idx > max) {
break;
}
}
}
public TreeNode[] NodeList;
public TreeNode Root;
public class TreeNode {
public TreeNode Parent;
public TreeNode Left;
public TreeNode Right;
public int ID;
public TreeNode(int id) {
this.ID = id;
}
public TreeNode AddChild(TreeNode cld) {
if(this.Left == null) {
this.Left = cld;
} else {
this.Right = cld;
}
cld.Parent = this;
return cld;
}
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
2
21
14
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番