답안 #1112848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112848 2024-11-15T02:52:57 Z ezzzay Zapina (COCI20_zapina) C++14
110 / 110
240 ms 2376 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(b>a)return 1;
    return modd(modd(arr[a]*mult[a-b])*mult[b]);
}
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;i++){
        mult[i]=fun(arr[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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 119 ms 1864 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 28 ms 1352 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 157 ms 1960 KB Output is correct
22 Correct 20 ms 1104 KB Output is correct
23 Correct 3 ms 628 KB Output is correct
24 Correct 41 ms 1404 KB Output is correct
25 Correct 24 ms 1104 KB Output is correct
26 Correct 50 ms 1556 KB Output is correct
27 Correct 224 ms 2120 KB Output is correct
28 Correct 223 ms 2120 KB Output is correct
29 Correct 227 ms 2120 KB Output is correct
30 Correct 231 ms 2124 KB Output is correct
31 Correct 225 ms 2352 KB Output is correct
32 Correct 228 ms 2376 KB Output is correct
33 Correct 234 ms 2316 KB Output is correct
34 Correct 231 ms 2288 KB Output is correct
35 Correct 238 ms 2224 KB Output is correct
36 Correct 240 ms 2376 KB Output is correct
37 Correct 237 ms 2376 KB Output is correct