Submission #344907

# Submission time Handle Problem Language Result Execution time Memory
344907 2021-01-06T17:38:48 Z limabeans Zapina (COCI20_zapina) C++17
110 / 110
510 ms 8556 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 355;


int n;
ll dp[maxn][maxn];

const int N = 1010;
ll f[N];
ll C[N][N];


void add(ll &x, ll y) {
    x %= mod;
    y %= mod;
    x += y;
    x %= mod;
}


ll solve(int i, int j, bool flag=false) {
    //cout<<i<<": "<<j<<endl;
    if (i==n) {
	if (flag) {
	    return i!=j;
	}
	return 1;
    }

    if (~dp[i][j]) return dp[i][j];
    ll &res = dp[i][j] = 0;

    // take x tasks
    for (int x=0; x<=j; x++) {
	if (flag) {
	    if (x==i) continue;
	}
	add(res, C[j][x]*solve(i+1,j-x,flag));
    }

    return res;
}



int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    f[0]=1;
    for (int i=1; i<N; i++) {
	f[i]=i*f[i-1]%mod;
    }

    for (int i=0; i<N; i++) {
	C[i][0]=C[i][i]=1;
	for (int j=1; j<i; j++) {
	    C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
    }

    assert(C[4][2]==6);
    

    cin>>n;
    memset(dp,-1,sizeof(dp));
    ll all = solve(1, n);


    memset(dp,-1,sizeof(dp));
    ll none = solve(1,n,true);


    ll res = all - none;
    
    res %= mod;
    res += mod;
    res %= mod;
    cout<<res<<endl;    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 6 ms 8300 KB Output is correct
3 Correct 6 ms 8328 KB Output is correct
4 Correct 6 ms 8320 KB Output is correct
5 Correct 6 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 6 ms 8300 KB Output is correct
3 Correct 6 ms 8328 KB Output is correct
4 Correct 6 ms 8320 KB Output is correct
5 Correct 6 ms 8300 KB Output is correct
6 Correct 6 ms 8300 KB Output is correct
7 Correct 6 ms 8300 KB Output is correct
8 Correct 6 ms 8300 KB Output is correct
9 Correct 6 ms 8300 KB Output is correct
10 Correct 6 ms 8300 KB Output is correct
11 Correct 6 ms 8300 KB Output is correct
12 Correct 6 ms 8300 KB Output is correct
13 Correct 6 ms 8300 KB Output is correct
14 Correct 6 ms 8320 KB Output is correct
15 Correct 6 ms 8300 KB Output is correct
16 Correct 6 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8300 KB Output is correct
2 Correct 6 ms 8300 KB Output is correct
3 Correct 6 ms 8328 KB Output is correct
4 Correct 6 ms 8320 KB Output is correct
5 Correct 6 ms 8300 KB Output is correct
6 Correct 6 ms 8300 KB Output is correct
7 Correct 6 ms 8300 KB Output is correct
8 Correct 6 ms 8300 KB Output is correct
9 Correct 6 ms 8300 KB Output is correct
10 Correct 6 ms 8300 KB Output is correct
11 Correct 6 ms 8300 KB Output is correct
12 Correct 6 ms 8300 KB Output is correct
13 Correct 6 ms 8300 KB Output is correct
14 Correct 6 ms 8320 KB Output is correct
15 Correct 6 ms 8300 KB Output is correct
16 Correct 6 ms 8300 KB Output is correct
17 Correct 266 ms 8428 KB Output is correct
18 Correct 7 ms 8300 KB Output is correct
19 Correct 60 ms 8416 KB Output is correct
20 Correct 6 ms 8300 KB Output is correct
21 Correct 333 ms 8556 KB Output is correct
22 Correct 44 ms 8300 KB Output is correct
23 Correct 9 ms 8300 KB Output is correct
24 Correct 81 ms 8300 KB Output is correct
25 Correct 50 ms 8300 KB Output is correct
26 Correct 99 ms 8428 KB Output is correct
27 Correct 467 ms 8436 KB Output is correct
28 Correct 473 ms 8556 KB Output is correct
29 Correct 472 ms 8556 KB Output is correct
30 Correct 477 ms 8436 KB Output is correct
31 Correct 483 ms 8428 KB Output is correct
32 Correct 510 ms 8428 KB Output is correct
33 Correct 495 ms 8436 KB Output is correct
34 Correct 497 ms 8556 KB Output is correct
35 Correct 502 ms 8436 KB Output is correct
36 Correct 503 ms 8436 KB Output is correct
37 Correct 505 ms 8556 KB Output is correct