結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー maimai
提出日時 2017-06-24 12:18:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 7,070 bytes
コンパイル時間 3,467 ms
コンパイル使用メモリ 210,876 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 22:29:59
合計ジャッジ時間 7,747 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 15 ms
6,940 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 20 ms
6,940 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 16 ms
6,944 KB
testcase_14 AC 21 ms
6,944 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 18 ms
6,940 KB
testcase_18 AC 28 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 1 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 29 ms
6,944 KB
testcase_50 AC 4 ms
6,940 KB
testcase_51 AC 4 ms
6,940 KB
testcase_52 AC 7 ms
6,944 KB
testcase_53 AC 4 ms
6,944 KB
testcase_54 AC 8 ms
6,940 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 4 ms
6,944 KB
testcase_57 AC 13 ms
6,940 KB
testcase_58 AC 24 ms
6,940 KB
testcase_59 AC 19 ms
6,940 KB
testcase_60 AC 9 ms
6,944 KB
testcase_61 AC 38 ms
6,940 KB
testcase_62 AC 10 ms
6,944 KB
testcase_63 AC 26 ms
6,940 KB
testcase_64 AC 7 ms
6,940 KB
testcase_65 AC 6 ms
6,944 KB
testcase_66 AC 9 ms
6,940 KB
testcase_67 AC 8 ms
6,940 KB
testcase_68 AC 9 ms
6,944 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,944 KB
testcase_71 AC 2 ms
6,944 KB
testcase_72 AC 2 ms
6,940 KB
testcase_73 AC 2 ms
6,944 KB
testcase_74 AC 2 ms
6,944 KB
testcase_75 AC 2 ms
6,944 KB
testcase_76 AC 2 ms
6,940 KB
testcase_77 AC 2 ms
6,940 KB
testcase_78 AC 2 ms
6,944 KB
testcase_79 AC 2 ms
6,944 KB
testcase_80 AC 2 ms
6,940 KB
testcase_81 AC 2 ms
6,944 KB
testcase_82 AC 2 ms
6,940 KB
testcase_83 AC 2 ms
6,940 KB
testcase_84 AC 2 ms
6,944 KB
testcase_85 AC 2 ms
6,944 KB
testcase_86 AC 2 ms
6,940 KB
testcase_87 AC 2 ms
6,940 KB
testcase_88 AC 2 ms
6,944 KB
testcase_89 AC 10 ms
6,944 KB
testcase_90 AC 17 ms
6,944 KB
testcase_91 AC 28 ms
6,940 KB
testcase_92 AC 6 ms
6,940 KB
testcase_93 AC 18 ms
6,944 KB
testcase_94 AC 3 ms
6,944 KB
testcase_95 AC 19 ms
6,940 KB
testcase_96 AC 16 ms
6,944 KB
testcase_97 AC 15 ms
6,940 KB
testcase_98 AC 8 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef long long int ll;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define repeat(l) for(auto cnt=0;cnt<(l);++cnt)
#define iterate(b,e) for(auto cnt=(b);cnt!=(e);++cnt)
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795
template<typename T1, typename T2>
ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())
namespace {
    std::chrono::system_clock::time_point ttt;
    void tic() { ttt = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - ttt)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}

/*
template<typename T>
//typedef double T;
class matrix {
public:
    size_t height, width;
    valarray<T> data;
    matrix(size_t height, size_t width) :height(height), width(width), data(height*width) {}
    matrix(size_t height, size_t width, const valarray<T>& data) :height(height), width(width), data(data) {}

    inline T& operator()(size_t y, size_t x) { return data[y*width + x]; }
    inline T operator() (size_t y, size_t x) const { return data[y*width + x]; }
    inline T& at(size_t y, size_t x) { return data[y*width + x]; }
    inline T at(size_t y, size_t x) const { return data[y*width + x]; }
    inline void resize(size_t h, size_t w) { height = h; width = w; data.resize(h*w); }
    inline void fill(T val) { data = val; }
    matrix<T>& setDiag(T val) { for (size_t i = 0, en = min(width, height); i < en; ++i)at(i, i) = val; return *this; }
    inline bool issquare() { return height == width; }

    void print(ostream& os) {
        os << "- - -" << endl; //  << setprecision(3)
        for (size_t y = 0; y < height; ++y) {
            for (size_t x = 0; x < width; ++x) {
                os << setw(7) << at(y, x) << ' ';
            }os << endl;
        }
    }
    template<typename MT> void copyto2d(MT& d2) {
        for (size_t i = 0; i < width*height; ++i) { d2[i / width][i%width] = data[i]; }
    }
    // mathematics
    void pow(long long) const;
    double det() const; T tr();
    matrix<T>& transpose_self(); matrix<T> transpose() const;
};

// IO
template<typename T> inline ostream& operator << (ostream& os, matrix<T> mat) { mat.print(os); return os; }

// スカラー
template<typename T> inline matrix<T>& operator+=(matrix<T>& mat, T val) { mat.data += val; return mat; }
template<typename T> inline matrix<T>& operator*=(matrix<T>& mat, T val) { mat.data *= val; return mat; }
template<typename T> inline matrix<T>& operator/=(matrix<T>& mat, T val) { mat.data /= val; return mat; }
template<typename T> inline matrix<T>& operator^=(matrix<T>& mat, T val) { mat.data ^= val; return mat; }

// 行列
template<typename T> inline matrix<T>& operator+=(matrix<T>& mat1, matrix<T>& mat2) { mat1.data += mat2.data; return mat1; }
template<typename T> inline matrix<T> operator+(matrix<T>& mat1, matrix<T>& mat2) { return matrix<T>(mat1.height, mat1.width, mat1.data + mat2.data); }

// 掛け算
template<typename T> matrix<T> multiply(const matrix<T>& mat1, const matrix<T>& mat2) {
    assert(mat1.width == mat2.height);
    matrix<T> result(mat1.height, mat2.width);
    for (size_t i = 0, j, k; i < mat1.height; i++) {
        for (j = 0; j < mat2.width; j++) {
            for (k = 0; k < mat1.width; k++) {
                result(i, j) += mat1(i, k) * mat2(k, j);
            }
        }
    }
    return result;
}
template<typename T> valarray<T> multiply(const matrix<T>& mat1, const valarray<T>& vec2) {
    assert(mat1.width == vec2.size());
    valarray<T> result(mat1.height);
    for (size_t i = 0, j; i < mat1.height; i++) {
        for (j = 0; j < mat1.width; j++) {
            result[i] += mat1(i, j) * vec2[j];
        }
    }
    return result;
}
template<typename T> inline matrix<T>& operator*=(matrix<T>& mat1, matrix<T>& mat2) { mat1 = multiply(mat1, mat2); return mat1; }
template<typename T> inline matrix<T> operator*(matrix<T>& mat1, matrix<T>& mat2) { return multiply(mat1, mat2); }
*/

class llmod {
public: const ll MOD = MD;
private:
    ll val;
    inline ll cut(ll v) const { return ((v%MOD) + MOD) % MOD; }
public:

    llmod() : MOD(MD), val(0) {}
    llmod(ll num,ll m = MD) : MOD(m),val(cut(num)) {}
    llmod(const llmod& lm, ll m) : MOD(m), val(lm.val) {}

    inline ll operator*() const { return val; }
    inline llmod& operator=(const llmod& lm) { val = lm.val; return *this; }
    inline llmod& operator=(ll v) { val = cut(v); return *this; }

    inline llmod& operator+=(ll v) { val = cut(val + v); return *this; }
    inline llmod& operator+=(const llmod& l) { val = cut(val + l.val); return *this; }
    inline llmod& operator-=(ll v) { val = cut(val - v); return *this; }
    inline llmod& operator-=(const llmod& l) { val = cut(val - l.val); return *this; }
    inline llmod& operator*=(ll v) { val = cut(val * v); return *this; }
    inline llmod& operator*=(const llmod& l) { val = cut(val * l.val); return *this; }
};
ostream& operator<<(ostream& os, const llmod& l) { os << *l; return os; }

inline llmod operator+(llmod t, const llmod& r) {return t += r; }
inline llmod operator-(llmod t, const llmod& r) { return t -= r; }
inline llmod operator*(llmod t, const llmod& r) { return t *= r; }

// MEMO : 逆元...powm(n,MD-2)
llmod pow(llmod x, ll p) {
    llmod y = 1;
    while (0 < p) {
        if (p % 2)
            y *= x;
        x *= x;
        p /= 2;
    }
    return y;
}

inline llmod& operator/=(llmod& l, const llmod& r) { return l *= pow(r, r.MOD - 2); }





int main() {
    int i, j, k, l;

    ll m, n;

    cin >> m;

    ll space = m + 1;

    for (n = 0; 0<scanf("%d", &k); n++) {
        space -= k + 1;
        if (k == 0) { cout << 1 << endl; return 0; }
    }
    if (space<0) {
        cout << "NA" << endl;
        return 0;
    }
    else if (space == 0) {
        cout << 1 << endl;
        return 0;
    }
    //printf("%d %d\n",space,n+1);
    llmod result = 1;
    llmod a = space, b = space - n;

    for (llmod a = space + n; space < *a; a -= 1) {
        result *= a;
    }
    for (; 0 < n; --n) {
        result /= n;
    }

    cout << result << endl;

    return 0;
}
0