結果

問題 No.462 6日知らずのコンピュータ
ユーザー mban
提出日時 2016-12-22 13:25:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,256 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 112,504 KB
実行使用メモリ 29,592 KB
最終ジャッジ日時 2024-12-14 14:21:44
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 62 WA * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{
    static int N, K;
   const long MOD = 1000000007;
    static void Main()
    {
  
        string[] s = Console.ReadLine().Split(' ');
        N = int.Parse(s[0]);
        K = int.Parse(s[1]);
        if (K == 0)
        {
            Console.WriteLine(kaijou(N));
            return;
        }
        long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        Array.Sort(a);
        long b = 0;
        long result = 1;
        for(int i = 0; i < K; i++)
        {
            if (!check(b, a[i]))
            {
                Console.WriteLine(0);
                return;
            }
         //   Console.WriteLine(count(b, a[i]));
          result*=  count(b, a[i]);
            result %= MOD;
            b = a[i];
        }

        result *= count(b, MyPow(2, N));
        Console.WriteLine(result % MOD);


    }

    static long count(long a,long b)
    {
        int cnt = 0;
        for(int i = 0; i < N; i++)
        {
            if (a % 2 <b %2)
            {
                cnt++;
            }
            a /= 2;
            b /= 2;
        }
     //   Console.WriteLine(cnt);
        return kaijou(cnt);
    }
    static bool check(long a,long b)
    {
        
        for (int i = 0; i < N; i++)
        {
            if (a % 2> b % 2)
            {
               
                return false;
            }
            a /= 2;
            b /= 2;
        }
        //Console.WriteLine("a");
        return true;
    }
    static long MyPow(long a,long b)
    {
        long result = 1;
        while (b > 0)
        {
            if (b % 2 == 0)
            {
                a *= a;
           //     a %= MOD;
                b /= 2;
            }
            else
            {
                result *= a;
          //      result %= MOD;
                b--;
            }

        }
        return result;
    }
    static long kaijou(long n)
    {
        if (n == 0)
        {
            return 1;
        }
        else
        {
            return n * kaijou(n - 1) % MOD;
        }
    }
}
0