Submission #316346

# Submission time Handle Problem Language Result Execution time Memory
316346 2020-10-26T04:08:55 Z LifeHappen__ Kangaroo (CEOI16_kangaroo) C++14
0 / 100
0 ms 384 KB
/*
https://oj.uz/problem/view/CEOI16_kangaroo
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ar array
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))

const int N=2005;
const int mod=1e9+7;
int n,cs,cf;
int f[N][N];

void add(int &x,int y){
   x=(x+y);
   if(x>=mod) x-=mod;
}

int32_t main(){
   fasty;

   #ifdef LOCAL
   freopen("in.txt", "r", stdin);
   #endif // LOCAL

   cin>>n>>cs>>cf;
   if(cs>cf) swap(cs,cf);
   f[1][0]=1;
   forinc(i,1,n){
      forinc(j,0,i){
         if(i==cs || i==cf){
            add(f[i+1][j], f[i][j]);
            if(j) add(f[i+1][j-1], f[i][j]);
         } else{
            if(j>1) add(f[i+1][j-1], j*(j-1)%mod*f[i][j]%mod);
            if(i>cs && j) add(f[i+1][j-1], f[i][j]*j%mod);
            if(i>cf && j) add(f[i+1][j-1], f[i][j]*j%mod);
            add(f[i+1][j+1], f[i][j]);
         }
      }
   }
   cout<<f[n][0];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct