結果
| 問題 |
No.411 昇順昇順ソート
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-09-02 01:37:37 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 2,445 bytes |
| コンパイル時間 | 1,219 ms |
| コンパイル使用メモリ | 107,520 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-11-15 17:25:12 |
| 合計ジャッジ時間 | 3,867 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
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;
int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
this.itemCount = inpt[0];
int start = inpt[1];
int flag = (1 << start);
long ans = this.GetAns(start, flag, false);
Console.WriteLine(ans);
}
private int itemCount;
private long GetAns(int num, int flag, bool useDesc)
{
int max = (1 << (itemCount + 1)) - 2;
if (max == flag)
{
if (useDesc)
{
return 1;
} else {
return 0;
}
}
long ans = 0;
if (useDesc)
{
for (int i = 1; i <= itemCount; i++)
{
int key = 1 << i;
if ((flag & key) == 0)
{
if (i > num)
{
ans++;
}
break;
}
}
}
else
{
for (int i = 1; i <= itemCount; i++)
{
int key = 1 << i;
if ((flag & key) != 0)
{
continue;
}
if (i < num)
{
if (useDesc)
{
continue;
}
ans += this.GetAns(i, flag + key, true);
}
else
{
ans += this.GetAns(i, flag + key, useDesc);
}
}
}
return ans;
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
2 1
";
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番