結果

問題 No.1644 Eight Digits
ユーザー bluemegane
提出日時 2021-08-14 07:04:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 174 ms / 1,000 ms
コード長 1,131 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 114,124 KB
実行使用メモリ 31,424 KB
最終ジャッジ日時 2024-10-04 15:40:24
合計ジャッジ時間 6,550 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 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()
    {
        var k = int.Parse(Console.ReadLine().Trim());
        var count = 0;
        var a = "12345678".ToCharArray().Perm();
        foreach (var x in a)
        {
            var b = int.Parse(string.Join("", x));
            if (b % k == 0) count++;
        }
        Console.WriteLine(count);
    }
}
0