結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー | alpha_virginis |
提出日時 | 2016-10-27 07:41:50 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,427 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 32,896 KB |
実行使用メモリ | 12,036 KB |
最終ジャッジ日時 | 2024-11-24 04:00:34 |
合計ジャッジ時間 | 3,412 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
11,808 KB |
testcase_01 | AC | 9 ms
11,672 KB |
testcase_02 | AC | 9 ms
11,868 KB |
testcase_03 | AC | 8 ms
11,844 KB |
testcase_04 | WA | - |
testcase_05 | AC | 9 ms
11,744 KB |
testcase_06 | AC | 9 ms
11,712 KB |
testcase_07 | AC | 9 ms
11,672 KB |
testcase_08 | AC | 9 ms
11,712 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 11 ms
11,928 KB |
testcase_13 | AC | 24 ms
11,676 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 36 ms
11,888 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 9 ms
11,848 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 10 ms
11,808 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 10 ms
11,944 KB |
testcase_45 | AC | 10 ms
11,868 KB |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | AC | 36 ms
11,764 KB |
testcase_50 | AC | 11 ms
11,796 KB |
testcase_51 | AC | 11 ms
11,680 KB |
testcase_52 | AC | 14 ms
11,728 KB |
testcase_53 | AC | 11 ms
11,776 KB |
testcase_54 | AC | 14 ms
11,680 KB |
testcase_55 | AC | 9 ms
11,724 KB |
testcase_56 | AC | 11 ms
11,704 KB |
testcase_57 | AC | 21 ms
11,756 KB |
testcase_58 | AC | 31 ms
11,800 KB |
testcase_59 | AC | 28 ms
11,900 KB |
testcase_60 | AC | 18 ms
11,768 KB |
testcase_61 | AC | 47 ms
11,768 KB |
testcase_62 | AC | 18 ms
11,800 KB |
testcase_63 | AC | 32 ms
11,872 KB |
testcase_64 | AC | 14 ms
11,808 KB |
testcase_65 | AC | 12 ms
11,672 KB |
testcase_66 | AC | 15 ms
11,556 KB |
testcase_67 | AC | 16 ms
11,856 KB |
testcase_68 | AC | 15 ms
11,860 KB |
testcase_69 | AC | 8 ms
11,952 KB |
testcase_70 | AC | 9 ms
11,812 KB |
testcase_71 | AC | 8 ms
11,912 KB |
testcase_72 | AC | 9 ms
11,844 KB |
testcase_73 | AC | 10 ms
11,824 KB |
testcase_74 | AC | 9 ms
11,888 KB |
testcase_75 | AC | 9 ms
11,944 KB |
testcase_76 | AC | 8 ms
11,800 KB |
testcase_77 | AC | 9 ms
11,980 KB |
testcase_78 | AC | 9 ms
11,848 KB |
testcase_79 | AC | 10 ms
12,012 KB |
testcase_80 | AC | 10 ms
11,876 KB |
testcase_81 | AC | 8 ms
11,852 KB |
testcase_82 | AC | 9 ms
11,960 KB |
testcase_83 | AC | 9 ms
11,752 KB |
testcase_84 | AC | 9 ms
11,864 KB |
testcase_85 | AC | 10 ms
11,796 KB |
testcase_86 | AC | 8 ms
11,856 KB |
testcase_87 | AC | 9 ms
11,868 KB |
testcase_88 | AC | 8 ms
11,780 KB |
testcase_89 | AC | 18 ms
11,952 KB |
testcase_90 | AC | 24 ms
11,824 KB |
testcase_91 | AC | 36 ms
11,920 KB |
testcase_92 | AC | 12 ms
11,812 KB |
testcase_93 | AC | 24 ms
12,024 KB |
testcase_94 | AC | 9 ms
11,836 KB |
testcase_95 | AC | 25 ms
11,816 KB |
testcase_96 | AC | 24 ms
11,868 KB |
testcase_97 | AC | 21 ms
11,904 KB |
testcase_98 | AC | 15 ms
11,924 KB |
ソースコード
#include <cstdio> #include <cassert> template<long size, long mod> struct smallCombinationTable { long table[size][size]; smallCombinationTable() { table[0][0] = 1; for(int i = 1; i < size; ++i) { table[i][0] = table[i][i] = 1; for(int j = 1; j < i; ++j) { table[i][j] = (table[i-1][j-1] + table[i-1][j]) % mod; } } } long operator() (long n, long r) { assert( 0 <= n and n < size ); assert( 0 <= r and r < size ); return table[n][r]; } }; template<long size, long mod> struct factorialTable { long table[size]; factorialTable() { table[0] = 1; for(int i = 1; i < size; ++i) { table[i] = (table[i-1] * i) % mod; } } long operator() (long n) { assert( 0 <= n and n < size ); return table[n]; } }; template<typename T> T pow(T x, long n) { T res = 1; T p = x; while( n != 0 ) { if( n & 0x01 ) res *= p; p *= p; n >>= 1; } return res; } template<long P = 1000000007> struct Mod { Mod() : a(0) {} Mod(long x) : a(x) {} long get() { return a; } Mod operator + (Mod x) { return Mod<P>((a + x.get()) % P); } Mod operator += (Mod x) { a = (a + x.get()) % P; return *this; } Mod operator - (Mod x) { return Mod<P>((a + P - x.get()) % P); } Mod operator -= (Mod x) { a = (a + P - x.a) % P; return *this; } Mod operator * (Mod x) { return Mod<P>((a * x.get()) % P); } Mod operator *= (Mod x) { a = (a * x.a) % P; return *this; } Mod operator / (Mod x) { return *this * pow(x, P - 2); } Mod operator /= (Mod x) { a = (*this * pow(x, P - 2)); return *this; } long a; }; template<long size, long mod> struct Combination { factorialTable<size, mod> factorial; long operator() (long n, long r) { Mod<mod> res = Mod<mod>(factorial(n)) / Mod<mod>(factorial(r) * factorial(n-r)); return res.get(); } }; Combination<1123456, 1000000007> combination; int main() { long m; long temp; long total = 0; long count = 0; scanf("%ld\n", &m); for(;;) { int c = getchar(); if( c == '\n' ) break; ungetc(c, stdin); scanf("%ld", &temp); total += temp; count += 1; } if( count == 1 and total == 0 ) { printf("1\n"); return 0; } long n = count + 1; long r = m - total - (count - 1); // printf("(n, r) = (%ld, %ld)\n", n, r); if( r < 0 ) { printf("NA\n"); return 0; } printf("%ld\n", combination(n + r - 1, r)); return 0; }