結果

問題 No.462 6日知らずのコンピュータ
ユーザー mban
提出日時 2016-12-22 13:05:40
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,066 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 113,056 KB
実行使用メモリ 29,588 KB
最終ジャッジ日時 2024-12-14 14:20:51
合計ジャッジ時間 5,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 17 RE * 42
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = (long)1e7;
    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;
        }
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Array.Sort(a);
        int b = 0;
        long result = 1;
        for(int i = 0; i < K; i++)
        {
            if (!check(b, a[i]))
            {
                Console.WriteLine(0);
                return;
            }
          result*=  count(b, a[i]);
            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 == 0 && b %2== 1)
            {
                cnt++;
            }
            a /= 2;
            b /= 2;
        }
        return kaijou(cnt);
    }
    static bool check(long a,long b)
    {
        for (int i = 0; i < N; i++)
        {
            if (a % 2 == 1 && b % 2 == 0)
            {
                return false;
            }
            a /= 2;
            b /= 2;
        }
        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(int n)
    {
        if (n == 0)
        {
            return 1;
        }
        return n * kaijou(n - 1)%MOD;
    }
}
0