結果

問題 No.213 素数サイコロと合成数サイコロ (3-Easy)
コンテスト
ユーザー nola_suz
提出日時 2015-05-23 14:01:44
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,129 ms / 3,000 ms
コード長 5,160 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,724 ms
コンパイル使用メモリ 137,232 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-27 17:28:31
合計ジャッジ時間 5,204 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void mainmain()':
main.cpp:217:17: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' reading 1200 bytes from a region of size 1192 [-Wstringop-overread]
  217 |         vv[0][i]=v[i+1];
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/allocator.h:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_tree.h:66,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/map:64,
                 from main.cpp:5:
In member function '_Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = long long int]',
    inlined from 'static _Tp* std::allocator_traits<std::allocator<_Tp1> >::allocate(allocator_type&, size_type) [with _Tp = long long int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/alloc_traits.h:614:28,
    inlined from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = long long int; _Alloc = std::allocator<long long int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:387:33,
    inlined from 'void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = long long int; _Alloc = std::allocator<long long int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:405:44,
    inlined from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:341:26,
    inlined from 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]' at /home

ソースコード

diff #
raw source code

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int a[]={2,3,5,7,11,13};
int b[]={4,6,8,9,10,12};
vvll ret11;
vvll ret12;
vll ret2;
void calc(vvll &aa,vvll &bb){
    // vvll ret;
    initvv(ret11,150,150,0LL);
    rep(i,150) ret11[i][i]=1LL;
    rep(i,150){
        rep(j,150){
            ll tt=0LL;
            rep(k,150){
                tt+=aa[i][k]*bb[k][j];
                tt%=MOD;
            }
            ret11[i][j]=tt;
        }
    }
    ret11.swap(aa);
}
void foo(ll a,vvll &vv){
    initvv(ret12,150,150,0LL);
    rep(i,150) ret12[i][i]=1LL;
    while(a){
        if(a&1){
            calc(ret12,vv);
        }
        a/=2;
        calc(vv,vv);
    }
    ret12.swap(vv);
}
void foo2(vvll &vv,vll &a){
    rep(i,150) ret2[i]=0LL;
    rep(i,150){
        rep(j,150){
            ret2[i]+=vv[i][j]*a[j]%MOD;
            ret2[i]%=MOD;
        }
    }
    ret2.swap(a);
}
vint cc;
vvint aaa;
vvint bbb;
void fa(int x){
    if(x==0){
        aaa.PB(cc);
        return;
    }
    rep(i,6){
        cc.PB(a[i]);
        fa(x-1);
        cc.pop_back();
    }
}
void fb(int x){
    if(x==0){
        bbb.PB(cc);
        return;
    }
    rep(i,6){
        cc.PB(b[i]);
        fb(x-1);
        cc.pop_back();
    }
}
void mainmain(){
    ll n;
    cin>>n;
    ll aa,bb;
    cin>>aa>>bb;
    vvll vv;
    ret2=vll(150);
    vll v(150,0);
    // v[0]=1;
    bool f=false;
    if(n<150LL) f=true;
    ll ans=0;
    if(aa) fa(aa);
    if(bb) fb(bb);
    rep(i,aaa.size()){
        sort(ALL(aaa[i]));
    }
    rep(i,bbb.size()){
        sort(ALL(bbb[i]));
    }
    sort(ALL(aaa));
    sort(ALL(bbb));
    aaa.erase(unique(ALL(aaa)),aaa.end());
    bbb.erase(unique(ALL(bbb)),bbb.end());
    // dump(aaa.size());
    vll ta(150,0LL);
    vll tb(150,0LL);
    rep(i,aaa.size()){
        ll t=0LL;
        rep(j,aaa[i].size()){
            t+=aaa[i][j];
            t%=MOD;
        }
        ta[t]++;
    }
    rep(i,bbb.size()){
        ll t=0LL;
        rep(j,bbb[i].size()){
            t+=bbb[i][j];
            t%=MOD;
        }
        tb[t]++;
    }
    // cout<<v[0]<<endl;
    if(aa==0||bb==0){
        rep(i,150) v[i]=ta[i]+tb[i];
    }
    else rep(i,150){
        rep(j,150){
            if(i+j>=150) break;
            if(ta[i]==0||tb[j]==0) continue;
            v[i+j]+=ta[i]*tb[j];
            v[i+j]%=MOD;
        }
    }
    initvv(vv,150,150,0LL);
    reep(i,1,150){
        vv[i][i-1]=1LL;
    }
    rep(i,150){
        vv[0][i]=v[i+1];
        // cout<<"b "<<i<<" "<<v[i]<<endl;
    }
    vvll ttt=vv;
    // rep(i,150) if(vv[0][i]) cout<<i<<" "<<vv[0][i]<<endl;
    foo(n,vv);
    // rep(i,150){
        // if(vv[0][i]) cout<<i<<" "<<vv[0][i]<<" "<<v[i]<<endl;
    // }cout<<endl;
    vll xx(150,0LL);
    xx[0]=1LL;
    foo2(vv,xx);
    // rep(i,150) if(v[i]) cout<<i<<" "<<v[i]<<endl;
    ans=0LL;
    // ans+=v[149];
    // v[149]=0LL;
    // vvll yy;
    // initvv(yy,150,150,0LL);
    // rep(i,150) yy[i][i]=1LL;
    // foo2(yy,xx);
    // rep(i,150){
        // cout<<xx[i]<<endl;
    // }
    // return;
    // int cnt=160;
    rep(i,149){
        // bool f=false;
        // rep(i,150) if(v[i]) f=true;
        // if(!f) break;
        // cout<<i<<" "<<xx[0]<<endl;
        ans+=xx[0];
        ans%=MOD;
        rep(j,i+1) xx[j]=0LL;
        foo2(ttt,xx);
        // cnt--;
        // if(cnt==0) break;
    }
    cout<<ans<<endl;
    // printf("%.13lf\n",ans);
}


signed main() {
    mainmain();
}
0