Submission #1112841

# Submission time Handle Problem Language Result Execution time Memory
1112841 2024-11-15T02:43:47 Z ezzzay Zapina (COCI20_zapina) C++14
22 / 110
307 ms 21572 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=355;
int dp[N][N][2];
const int mod=1e9+7;
int arr[N];
int mult[N*N*10];
int modd(int a){
    return((a%mod+mod)%mod);
}
int fun(int a, int b){
    int ans=1;
    for(int i=0;i<=31;i++){
        if(b&(1<<i)){
            ans=modd((ans*a));
        }
        a=modd(a*a);
    }
    return ans;
}
int find(int a, int b){
    if(a==b)return 1;
    if(a==0 or b==0)return 1;
    int p=(arr[b]%mod*(arr[a-b]%mod))%mod;

    return arr[a]%mod*mult[p]%mod;
}
signed main(){
    arr[0]=1;
    for(int i=1;i<N;i++){
        arr[i]=arr[i-1]*i%mod;
    }
    
    for(int i=0;i<N*N*10;i++){
        mult[i]=fun(i,mod-2);
    }
    int n;
    cin>>n;
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                if(j+k>n)break;
                if(k==i){
                    dp[i][j+k][1]+=(dp[i-1][j][1]+dp[i-1][j][0])*find(n-j,k);
                   
                }
                else{
                    dp[i][j+k][1]+=dp[i-1][j][1]*find(n-j,k);
                    dp[i][j+k][0]+=dp[i-1][j][0]*find(n-j,k);
                }
                dp[i][j+k][1]%=mod;
                dp[i][j+k][0]%=mod;
               
            }
        }
    }
    cout<<dp[n][n][1];
}
# Verdict Execution time Memory Grader output
1 Correct 291 ms 10824 KB Output is correct
2 Correct 291 ms 10720 KB Output is correct
3 Correct 281 ms 10824 KB Output is correct
4 Correct 280 ms 10832 KB Output is correct
5 Correct 289 ms 10824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 291 ms 10824 KB Output is correct
2 Correct 291 ms 10720 KB Output is correct
3 Correct 281 ms 10824 KB Output is correct
4 Correct 280 ms 10832 KB Output is correct
5 Correct 289 ms 10824 KB Output is correct
6 Correct 291 ms 10824 KB Output is correct
7 Runtime error 307 ms 21572 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 291 ms 10824 KB Output is correct
2 Correct 291 ms 10720 KB Output is correct
3 Correct 281 ms 10824 KB Output is correct
4 Correct 280 ms 10832 KB Output is correct
5 Correct 289 ms 10824 KB Output is correct
6 Correct 291 ms 10824 KB Output is correct
7 Runtime error 307 ms 21572 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -