結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー 6v86v8
提出日時 2016-07-09 04:50:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,388 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 108,892 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-08-03 11:21:39
合計ジャッジ時間 6,081 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision


typedef long long ll;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}

const ll W = 1000000007LL;

map<pair<int,long>,ll> memo;

long g(int t){
    long x = 1;
    for(int i = 0 ; i<t;i++){x*=10;}
    return x;
}


ll kake(ll a, long k){
    if(a<k) return kake(k,a);
    ll ans = 0;
    vector<bool> b;
    b.push_back(k%2);
    while(k!=0){k>>=1; b.push_back(k%2);}
    reverse(b.begin(), b.end());
    for(auto i = b.begin();i!=b.end();i++){
        ans+=*i * a; ans%=W; ans<<=1;
    }
    ans>>=1;
    return ans;
}


ll getans(long m,vector<long> v , int cursor){
    long mysum = accumulate(v.begin(),v.end(), 0L)  + v.size() - 1 ;
    if(mysum == 0 ) return 1;
    if(mysum == m) return 1;
    if(mysum > m) return 0;
    long t = m - (accumulate(v.begin(),v.end(), 0L) + v.size() -1 ) + 1 + v.size() -1 ;
    long s = v.size();
    vector<long> ansl(s);
    for(int i = 0 ; i<s;i++){
        ansl[i] = t-i;
    }
    vector<int> l(s+1,0);
    
    for(long i = 1; i<=s;i++){
        long k = i;
        for(long j = 2; j<=sqrt(s);j++){
            while(k%j == 0) k/=j,l[j]++;
        }
        l[k]++;
    }
    
    for(long i = 1; i<=s;i++){
        while(l[i]>0){
            l[i]--;
            for(int  j = 0 ; j<s;j++){
                if(ansl[j]%i == 0){ansl[j]/=i; break;}
                assert(j!=s-1);
            }
        }
    }
    
    
    return accumulate(ansl.begin(),ansl.end(),1LL,[](ll sum , long k)->ll{return kake(sum,k);})%W;
}

           
int main(){
    omajinai();
    long m; cin>>m;
    cin.ignore();
    vector<long> v;
    string s;
    getline(cin,s);
    stringstream x(s);
    long t;
    while(x>>t){v.push_back(t);}
    string myans = to_string(getans(m,v,0));
    if(myans == "0") myans = "NA";
    cout<<myans<<endl;
    
    
}
0