結果

問題 No.462 6日知らずのコンピュータ
ユーザー AreTrash
提出日時 2016-12-13 06:39:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,594 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 110,208 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-11-30 00:41:16
合計ジャッジ時間 5,942 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

namespace No462_1{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var K = sr.Next<int>();
            var A = sr.Next<long>(K);

            const int mod = 1000000007;
            var mf = Ex.ModFac(100, mod);
            var a = A
                .Concat(new[]{0, (long)Math.Pow(2, N) - 1})
                .Select(x => Convert.ToString(x, 2).PadLeft(N, '0'))
                .OrderBy(x => x.Count(c => c == '1')).ToArray();

            var res = 1L;
            for(var i = 1; i < K + 2; i++){
                for(var j = 0; j < N; j++) if(a[i - 1][j] == '1' && a[i][j] == '0') res = 0L;
                res *= mf[a[i].Count(c => c == '1') - a[i - 1].Count(c => c == '1')];
                res %= mod;
            }

            Console.WriteLine(res);
            //---------------------------------
        }
    }

    public class Ex{
        public static long[] ModFac(int n, int mod){
            var ret = new long[n];
            ret[0] = 1;
            for(var i = 1; i < n; i++) ret[i] = ret[i - 1] * i % mod;
            return ret;
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}
0