結果

問題 No.462 6日知らずのコンピュータ
ユーザー 14番14番
提出日時 2016-12-14 07:58:55
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,495 bytes
コンパイル時間 2,964 ms
コンパイル使用メモリ 109,764 KB
実行使用メモリ 114,672 KB
最終ジャッジ日時 2023-08-20 06:31:23
合計ジャッジ時間 7,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
29,100 KB
testcase_01 AC 77 ms
24,084 KB
testcase_02 AC 89 ms
22,016 KB
testcase_03 AC 84 ms
21,948 KB
testcase_04 AC 79 ms
22,048 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Text;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;

        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        this.Length = inpt[0];
        if(inpt[1] == 0) {
            long ans = 1;
            for(int i=2; i<=this.Length; i++) {
                ans*=i;
                ans = ans % MOD;
            }
            Console.WriteLine(ans);
        } else {
            this.NumList = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).OrderBy(a=>a).ToArray();
            this.NumList = this.NumList.Where(a=>a!=((((long)1<<this.Length))-1)).ToArray();
            int maxKeta = Convert.ToString(this.NumList.Max(), 2).Length;
            char[] arr = new char[maxKeta].Select(a=>' ').ToArray();
            foreach(long item in this.NumList.OrderByDescending(a=>a)) {
                string tmp = Convert.ToString(item, 2);
                for(int i=0; i<tmp.Length; i++) {
                    if(tmp[tmp.Length-i-1] == '1' && arr[arr.Length-1-i] == '0') {
                        Console.WriteLine(0);
                        return;
                    }
                    if(tmp[tmp.Length-i-1] == '0') {
                        arr[arr.Length-1-i] = '0';
                    }
                }
            }

            long ans = this.GetAns(0,0);
            Console.WriteLine(ans);
        }
    }

    private Dictionary<long, long> dic = new Dictionary<long, long>();

    private long GetAns(long selected, long flags) {
        if(dic.ContainsKey(selected)) {
            return dic[selected];
        }

        long flags2 = flags;
        for(int i=0; i<this.NumList.Length; i++) {
            long key = (long)1<<i;
            if((flags2&key) == key) {
                continue;
            }
            if(selected == this.NumList[i]) {
                flags2+=key;
                continue;
            }
            if(selected > this.NumList[i]) {
                dic[selected] = 0;
                return 0;
            }
            string selStr = Convert.ToString(selected, 2);
            string numStr = Convert.ToString(this.NumList[i], 2);

            selStr = selStr.PadLeft(numStr.Length, '0');
            numStr = numStr.PadLeft(selStr.Length);
            bool flag = true;
            for(int j=numStr.Length -1; j>=0; j--) {
                if(numStr[j] == '0' && selStr[j] != '0') {
                    flag = false;
                    break;
                }
            }
            if(!flag) {
                dic[selected] = 0;
                return 0;
            }
        }
        if(selected == ((long)1<<this.Length)-1) {
            if(flags2 == ((long)1<<this.NumList.Length)-1) {
                dic[selected] = 1;
            } else {
                dic[selected] = 0;
            }
            return dic[selected];
        }
        if(flags2 == ((long)1<<this.NumList.Length)-1) {
            int cnt = 0;
            for(int i=0; i<this.Length; i++) {
                long key = (long)1<<i;
                if((selected&key)==0) {
                    cnt++;
                }
            }
            long ret = 1;
            for(int i=1; i<=cnt; i++) {
                ret*=i;
                ret = ret % MOD;
            }
            dic[selected] = ret;
            return ret;
        }
        long ans = 0;
        for(int i=0; i<this.Length; i++) {
            long key = (long)1<<i;
            if((selected&key)>0) {
                continue;
            }
            ans+=this.GetAns(selected+key, flags2);
            ans = ans % MOD;
        }
        this.dic[selected] = ans;
        return ans;
    }

    private const long MOD = 1000000000 + 7;

    private int Length = 0;

    private long[] NumList;
    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"

60 2
0 1152921504606846975

";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0