結果
問題 | No.411 昇順昇順ソート |
ユーザー |
![]() |
提出日時 | 2021-04-26 20:15:52 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,853 ms / 2,000 ms |
コード長 | 1,847 bytes |
コンパイル時間 | 3,962 ms |
コンパイル使用メモリ | 108,800 KB |
実行使用メモリ | 23,452 KB |
最終ジャッジ日時 | 2024-07-05 06:16:53 |
合計ジャッジ時間 | 14,507 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.Linq; using System.Collections.Generic; using System; public static class combi { public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r) { if (r == 0) { yield return Enumerable.Empty<T>(); } else { var i = 1; foreach (var x in items) { var xs = items.Skip(i); foreach (var c in Comb(xs, r - 1)) yield return c.Before(x); i++; } } } public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first) { yield return first; foreach (var i in items) yield return i; } } public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); getAns(n, k); } static void getAns(int n, int k) { var a = Enumerable.Range(1, n).ToList(); a.Remove(k); var count = 0; for (int i = 0; i < n - 1; i++) { var a0 = new List<int>(); var w = a.Comb(i); foreach (var x in w) { a0.Clear(); a0.Add(k); var used = new bool[n + 1]; used[k] = true; foreach (var y in x) { a0.Add(y); used[y] = true; } var minb = 0; for (int j = 1; j <= n; j++) { if (!used[j]) { minb = j; break; } } a0.Sort(); if (a0[0] == k && a0[i] > minb) count++; } } Console.WriteLine(count); } }