結果

問題 No.462 6日知らずのコンピュータ
ユーザー 14番14番
提出日時 2016-12-14 07:58:55
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,495 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 116,576 KB
実行使用メモリ 136,068 KB
最終ジャッジ日時 2024-11-30 07:04:55
合計ジャッジ時間 23,956 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
34,572 KB
testcase_01 AC 40 ms
34,332 KB
testcase_02 AC 52 ms
32,632 KB
testcase_03 AC 45 ms
97,092 KB
testcase_04 AC 41 ms
32,472 KB
testcase_05 TLE -
testcase_06 AC 43 ms
32,468 KB
testcase_07 AC 1,885 ms
115,180 KB
testcase_08 AC 31 ms
25,204 KB
testcase_09 AC 41 ms
25,584 KB
testcase_10 AC 41 ms
25,716 KB
testcase_11 AC 42 ms
27,744 KB
testcase_12 AC 43 ms
27,788 KB
testcase_13 AC 68 ms
25,992 KB
testcase_14 AC 53 ms
27,944 KB
testcase_15 AC 41 ms
23,728 KB
testcase_16 AC 86 ms
33,008 KB
testcase_17 TLE -
testcase_18 AC 43 ms
25,968 KB
testcase_19 AC 142 ms
39,180 KB
testcase_20 AC 44 ms
25,648 KB
testcase_21 AC 491 ms
44,948 KB
testcase_22 AC 107 ms
33,140 KB
testcase_23 AC 45 ms
27,676 KB
testcase_24 AC 44 ms
27,440 KB
testcase_25 AC 48 ms
27,844 KB
testcase_26 AC 86 ms
32,928 KB
testcase_27 AC 44 ms
25,540 KB
testcase_28 AC 41 ms
25,772 KB
testcase_29 AC 57 ms
27,588 KB
testcase_30 AC 55 ms
25,836 KB
testcase_31 TLE -
testcase_32 AC 47 ms
25,812 KB
testcase_33 AC 43 ms
28,008 KB
testcase_34 TLE -
testcase_35 AC 42 ms
25,844 KB
testcase_36 AC 52 ms
27,836 KB
testcase_37 AC 1,084 ms
52,176 KB
testcase_38 AC 43 ms
27,876 KB
testcase_39 AC 123 ms
32,388 KB
testcase_40 AC 46 ms
25,588 KB
testcase_41 AC 46 ms
23,868 KB
testcase_42 AC 48 ms
27,672 KB
testcase_43 AC 75 ms
33,132 KB
testcase_44 AC 44 ms
25,756 KB
testcase_45 AC 43 ms
27,884 KB
testcase_46 AC 50 ms
27,564 KB
testcase_47 AC 45 ms
25,628 KB
testcase_48 AC 60 ms
29,528 KB
testcase_49 AC 40 ms
23,476 KB
testcase_50 AC 39 ms
25,844 KB
testcase_51 AC 40 ms
25,588 KB
testcase_52 AC 41 ms
25,648 KB
testcase_53 AC 41 ms
25,644 KB
testcase_54 AC 39 ms
27,628 KB
testcase_55 AC 40 ms
25,604 KB
testcase_56 AC 40 ms
25,480 KB
testcase_57 AC 41 ms
25,484 KB
testcase_58 AC 41 ms
27,400 KB
testcase_59 AC 40 ms
25,596 KB
testcase_60 AC 41 ms
25,592 KB
testcase_61 AC 39 ms
25,716 KB
testcase_62 AC 44 ms
25,648 KB
testcase_63 AC 41 ms
25,476 KB
testcase_64 AC 40 ms
25,712 KB
testcase_65 AC 40 ms
27,500 KB
testcase_66 AC 41 ms
25,440 KB
testcase_67 AC 41 ms
25,520 KB
testcase_68 AC 41 ms
25,612 KB
testcase_69 AC 42 ms
25,836 KB
testcase_70 AC 41 ms
27,400 KB
testcase_71 AC 40 ms
25,644 KB
testcase_72 AC 41 ms
25,604 KB
testcase_73 AC 41 ms
25,588 KB
testcase_74 AC 41 ms
25,720 KB
testcase_75 AC 41 ms
25,496 KB
testcase_76 AC 39 ms
25,520 KB
testcase_77 AC 40 ms
27,644 KB
testcase_78 AC 41 ms
23,732 KB
testcase_79 AC 31 ms
25,336 KB
testcase_80 AC 30 ms
25,300 KB
testcase_81 AC 31 ms
27,100 KB
testcase_82 AC 31 ms
25,208 KB
testcase_83 AC 31 ms
27,128 KB
testcase_84 AC 42 ms
27,628 KB
testcase_85 AC 41 ms
25,648 KB
testcase_86 AC 31 ms
136,068 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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