結果

問題 No.411 昇順昇順ソート
ユーザー norioc
提出日時 2016-08-12 23:29:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 112,312 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-11-07 15:52:11
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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.

ソースコード

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