Submission #931351

# Submission time Handle Problem Language Result Execution time Memory
931351 2024-02-21T15:56:38 Z Whisper Zapina (COCI20_zapina) C++17
110 / 110
217 ms 2312 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using str = string;
// using T = tuple<double, ll, ll>;

#define int long long
#define Base 31
#define sz(a) (int)a.size()
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for ( int i = b ; i >= a ; i-- )
#define REP(i, n) for ( int i = 0 ; i < n ; ++i )
#define REPD(i, n) for ( int i =  n - 1 ; ~(--i) ; )
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define fi first
#define se second
#define Lg(x) 31 - __builtin_clz(x)

constexpr ll LINF = (1ll << 62);
constexpr int INF = (1ll << 31);
constexpr int MAX = 351;
constexpr int Mod = 1e9 + 7;

void setupIO( const string& PROB ){

    //Phu Trong from Nguyen Tat Thanh High School for gifted student

    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//    freopen( (PROB + ".inp").c_str(), "r", stdin);
//    freopen( (PROB + ".out").c_str(), "w", stdout);
    cout << fixed << setprecision(10);
}

int ifac[MAX], fac[MAX];

int power(int a, int b){
    int res = 1;
    for ( ; b; b >>= 1 , a = (a * a) % Mod) if(b & 1){
        res = (res * a) % Mod;
    }
    return res;
}
void genFac(int n){
    ifac[0] = fac[0] = 1;
    for(int i = 1 ; i <= n ; i++) fac[i] = fac[i - 1] * i % Mod;
    for(int i = 1 ; i <= n ; i++) ifac[i] = power(fac[i] , Mod - 2);
}

int c(int n , int k){
    assert(n >= k);
    return fac[n] * ifac[n - k] % Mod * ifac[k] % Mod;
}
int n;
int f[MAX][MAX][2];

//f(i, j, k): cách chia bánh cho i thằng đầu sao cho dư j cái bánh và đã có thằng thỏa mãn hay chưa
void Whisper(){ 
    int n; cin >> n;

    genFac(n);
    f[0][n][0] = 1;
    for ( int i = 1 ; i <= n ; i++ ){ // thằng thứ i
        for ( int j = 0 ; j <= n ; j++ ){ // còn dư j cái bánh
            for ( int k = 0 ; k <= j ; k++ ){ // cho thằng thứ i k cái bánh
                if (i == k){
                    f[i][j - k][1] += (f[i - 1][j][0] + f[i - 1][j][1]) % Mod * c(j , k);
                    f[i][j - k][1] %= Mod;
                }
                else{
                    (f[i][j - k][1] += (f[i - 1][j][1] * c(j , k)) % Mod) %= Mod;

                    (f[i][j - k][0] += (f[i - 1][j][0] * c(j , k)) % Mod)  %= Mod;
                }
            }
        }
    }
    cout << f[n][0][1];
}   
    
signed main(){
    setupIO("Whisper");
    int Test = 1;
    // cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 106 ms 1876 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 23 ms 1296 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 141 ms 2092 KB Output is correct
22 Correct 16 ms 1116 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 30 ms 1368 KB Output is correct
25 Correct 21 ms 1204 KB Output is correct
26 Correct 41 ms 1388 KB Output is correct
27 Correct 196 ms 2128 KB Output is correct
28 Correct 200 ms 2132 KB Output is correct
29 Correct 201 ms 2132 KB Output is correct
30 Correct 205 ms 2276 KB Output is correct
31 Correct 205 ms 2292 KB Output is correct
32 Correct 211 ms 2280 KB Output is correct
33 Correct 207 ms 2132 KB Output is correct
34 Correct 209 ms 2288 KB Output is correct
35 Correct 211 ms 2128 KB Output is correct
36 Correct 217 ms 2132 KB Output is correct
37 Correct 215 ms 2312 KB Output is correct