結果

問題 No.411 昇順昇順ソート
ユーザー 14番14番
提出日時 2016-09-02 01:37:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 2,445 bytes
コンパイル時間 4,954 ms
コンパイル使用メモリ 105,560 KB
実行使用メモリ 24,116 KB
最終ジャッジ日時 2023-08-09 20:08:16
合計ジャッジ時間 6,783 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,868 KB
testcase_01 AC 58 ms
21,928 KB
testcase_02 AC 60 ms
21,932 KB
testcase_03 AC 59 ms
23,852 KB
testcase_04 AC 57 ms
21,924 KB
testcase_05 AC 56 ms
21,772 KB
testcase_06 AC 58 ms
21,940 KB
testcase_07 AC 60 ms
23,992 KB
testcase_08 AC 58 ms
21,824 KB
testcase_09 AC 59 ms
21,848 KB
testcase_10 AC 59 ms
21,816 KB
testcase_11 AC 56 ms
22,068 KB
testcase_12 AC 59 ms
22,024 KB
testcase_13 AC 57 ms
21,932 KB
testcase_14 AC 57 ms
22,068 KB
testcase_15 AC 59 ms
23,824 KB
testcase_16 AC 59 ms
23,860 KB
testcase_17 AC 59 ms
21,984 KB
testcase_18 AC 57 ms
19,808 KB
testcase_19 AC 58 ms
24,116 KB
testcase_20 AC 59 ms
23,920 KB
testcase_21 AC 58 ms
19,880 KB
testcase_22 AC 59 ms
23,876 KB
testcase_23 AC 60 ms
21,984 KB
testcase_24 AC 61 ms
23,828 KB
testcase_25 AC 58 ms
21,788 KB
testcase_26 AC 59 ms
24,032 KB
testcase_27 AC 58 ms
21,980 KB
testcase_28 AC 142 ms
23,976 KB
testcase_29 AC 76 ms
19,812 KB
testcase_30 AC 59 ms
21,892 KB
testcase_31 AC 58 ms
22,012 KB
testcase_32 AC 59 ms
23,892 KB
testcase_33 AC 58 ms
21,860 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0