Submission #597735

# Submission time Handle Problem Language Result Execution time Memory
597735 2022-07-16T18:27:52 Z Deepesson NoM (RMI21_nom) C++17
52 / 100
16 ms 12192 KB
#include <bits/stdc++.h>
#define MAX 905


using ll  = long long;
const ll MOD = 1e9+7;

ll binominal[MAX][MAX];
bool exbin[MAX][MAX];
ll dpbin(int a,int b){
    if(!b)return 1;
    if(!a)return 0;
    if(exbin[a][b])return binominal[a][b];
    exbin[a][b]=true;
    return binominal[a][b] = (dpbin(a-1,b)+dpbin(a-1,b-1))%MOD;
}

bool existe[MAX][MAX];
ll tab[MAX][MAX];
ll fat[MAX];
std::vector<int> tamanhos;
ll dp(int nunca_pegou,int pegou_uma_vez,int seq){
    if(seq==tamanhos.size()){
        //std::cout<<"Chegou! "<<nunca_pegou+pegou_uma_vez<<"\n";
        if(nunca_pegou+pegou_uma_vez==0)
            return 1;
        return 0;
    }
    if(existe[nunca_pegou][pegou_uma_vez])return tab[nunca_pegou][pegou_uma_vez];
    existe[nunca_pegou][pegou_uma_vez]=true;
   // std::cout<<nunca_pegou<<" "<<pegou_uma_vez<<" "<<seq<<"\n";
    int tem_q_pegar = tamanhos[seq];
    ll resposta=0;
    for(int i=0;i<=std::min(tem_q_pegar,pegou_uma_vez);++i){
        int necessita = tem_q_pegar-i;
        if(nunca_pegou<necessita)continue;
        ll chance1 = dpbin(nunca_pegou,necessita);
        ll chance2 = dpbin(pegou_uma_vez,i);
        ll total = (chance1*chance2)%MOD;
        ll res = dp(nunca_pegou-necessita,pegou_uma_vez-i+necessita,seq+1);
        ll totalres = (total*res)%MOD;
        ll fatty = fat[tem_q_pegar];
        ll truetotral = (fatty*totalres)%MOD;
        resposta=(resposta+truetotral)%MOD;
    }
    return tab[nunca_pegou][pegou_uma_vez]=resposta;
}

int main()
{
   // std::cout<<dpbin(10,6)<<"\n";
    int N,M;
    std::cin>>N>>M;
    fat[0]=1;
    for(int i=1;i!=MAX;++i)fat[i]=(fat[i-1]*i)%MOD;
    {
        int x = (2*N)/M;
        for(int i=0;i!=M;++i)tamanhos.push_back(x);
        for(int i=0;i!=((2*N)%M);++i)tamanhos[i]++;
        ll xa=0;
        for(int i=0;i!=M;++i){
            xa+=tamanhos[i];
            //std::cout<<tamanhos[i]<<" \n"[i==M-1];
        }
        assert(xa==(2*N));
    }
    ll bonus=1;
    for(int i=0;i!=N;++i)bonus=(bonus*2)%MOD;
    std::cout<<((dp(N,0,0)*bonus)%MOD)<<"\n";
}

Compilation message

Main.cpp: In function 'll dp(int, int, int)':
Main.cpp:23:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if(seq==tamanhos.size()){
      |        ~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3088 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 3 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3088 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 3 ms 3540 KB Output is correct
28 Correct 9 ms 7564 KB Output is correct
29 Correct 12 ms 8204 KB Output is correct
30 Correct 11 ms 8020 KB Output is correct
31 Correct 7 ms 7640 KB Output is correct
32 Correct 9 ms 8532 KB Output is correct
33 Correct 11 ms 8888 KB Output is correct
34 Correct 16 ms 11352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3088 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 3 ms 3540 KB Output is correct
28 Correct 9 ms 7564 KB Output is correct
29 Correct 12 ms 8204 KB Output is correct
30 Correct 11 ms 8020 KB Output is correct
31 Correct 7 ms 7640 KB Output is correct
32 Correct 9 ms 8532 KB Output is correct
33 Correct 11 ms 8888 KB Output is correct
34 Correct 16 ms 11352 KB Output is correct
35 Runtime error 12 ms 12192 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -