結果
問題 | No.462 6日知らずのコンピュータ |
ユーザー |
![]() |
提出日時 | 2016-12-22 13:30:53 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 2,258 bytes |
コンパイル時間 | 1,144 ms |
コンパイル使用メモリ | 111,468 KB |
実行使用メモリ | 27,396 KB |
最終ジャッジ日時 | 2024-12-14 14:21:50 |
合計ジャッジ時間 | 5,317 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.
ソースコード
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)-1); 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; } } }