結果

問題 No.411 昇順昇順ソート
ユーザー noriocnorioc
提出日時 2016-08-12 23:29:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 3,527 ms
コンパイル使用メモリ 103,256 KB
実行使用メモリ 23,944 KB
最終ジャッジ日時 2023-08-07 11:56:30
合計ジャッジ時間 6,098 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,876 KB
testcase_01 AC 59 ms
22,024 KB
testcase_02 AC 60 ms
21,972 KB
testcase_03 AC 60 ms
21,868 KB
testcase_04 AC 59 ms
21,956 KB
testcase_05 AC 60 ms
21,960 KB
testcase_06 AC 60 ms
21,812 KB
testcase_07 AC 60 ms
21,824 KB
testcase_08 AC 60 ms
23,904 KB
testcase_09 AC 60 ms
23,860 KB
testcase_10 AC 60 ms
21,904 KB
testcase_11 AC 60 ms
23,872 KB
testcase_12 AC 60 ms
21,764 KB
testcase_13 AC 60 ms
21,976 KB
testcase_14 AC 60 ms
22,056 KB
testcase_15 AC 60 ms
23,908 KB
testcase_16 AC 60 ms
23,856 KB
testcase_17 AC 60 ms
23,940 KB
testcase_18 AC 59 ms
21,908 KB
testcase_19 AC 59 ms
21,744 KB
testcase_20 AC 60 ms
23,944 KB
testcase_21 AC 60 ms
21,900 KB
testcase_22 AC 59 ms
21,860 KB
testcase_23 AC 61 ms
21,888 KB
testcase_24 AC 59 ms
21,976 KB
testcase_25 AC 59 ms
21,776 KB
testcase_26 AC 59 ms
21,812 KB
testcase_27 AC 61 ms
19,868 KB
testcase_28 AC 204 ms
21,900 KB
testcase_29 AC 97 ms
21,864 KB
testcase_30 AC 71 ms
21,768 KB
testcase_31 AC 71 ms
21,864 KB
testcase_32 AC 71 ms
21,812 KB
testcase_33 AC 72 ms
21,824 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.Linq;

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

/*
    static long Combination(int n, int r) {
        long num = 1;
        long den = 1;
        for (int i = 0; i < r; i++) {
            num *= n - i;
            den *= r - i;
        }
        return num / den;
    }

    static long Calc(int n, int k) {
        if (k == 1 && n == 2) return 0;

        long sum = 0;
        int p = n - k;
        for (int i = 0; i <= p; i++) {
            sum += Combination(p, i);
        }
        return sum;
    }
*/
    static int Calc(int n, int k) {
        int ans = 0;
        var xs = new bool[n];
        for (int i = 1; i < (1 << n); i++) {
            int max = 0;
            int min = int.MaxValue;
            bool ng = false;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) != 0) {
                    if (j < k) { // 先頭は k なのでスキップ
                        ng = true;
                        break;
                    }
                    xs[j] = true;
                    max = j;
                }
                else {
                    xs[j] = false;
                    min = Math.Min(min, j);
                }
            }

            if (ng) continue;

            if (xs[k] && max > min) {
                ans++;
            }
        }
        return ans;
    }

    static void Main() {
        var xs = ReadInts();
        int n = xs[0], k = xs[1];
        Console.WriteLine(Calc(n, k-1));
    }
}
0