Submission #741044

#TimeUsernameProblemLanguageResultExecution timeMemory
741044Bogdan1110Kangaroo (CEOI16_kangaroo)C++14
100 / 100
114 ms42504 KiB
#include <bits/stdc++.h>
#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
 
void files() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}


const double eps = 0.00000001;
const int NMAX = 2020;
const ll inf = LLONG_MAX/3;
const ll modi = 1e9+7;


    int s,t;

int calc[NMAX][NMAX];
ll memo[NMAX][NMAX];
ll dp(int i, int j){
    if ( j > i ) return 0;
    if ( i == 1 ) {
        if ( j == 1 ) {
            return 1;
        }
        return 0;
    }
    if ( calc[i][j] ) {
        return memo[i][j];
    }
    if ( i == s || i == t ) {
        memo[i][j] = dp(i-1,j-1) + dp(i-1,j);
        memo[i][j] %= modi;
    }
    else {
        memo[i][j] = dp(i-1,j-1) * (j-(i>s)-(i>t));
        memo[i][j] %= modi;
        memo[i][j] += (dp(i-1,j+1) * (j))%modi;
        memo[i][j] %= modi;
    }

    calc[i][j] = 1;
    return memo[i][j];
}

void solve() {
    int n;
    cin >> n;
    cin >> s >> t;

    cout << dp(n,1);

}

int main () { 
    FAST

    int t=1;

    /*
    cin >> t;
    //*/

    int i = 1;
    while(t--) {
        //cout << "Case #" << i++ << ": " ;
        solve();
    }
}  

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:88:9: warning: unused variable 'i' [-Wunused-variable]
   88 |     int i = 1;
      |         ^
kangaroo.cpp: In function 'void files()':
kangaroo.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...