Submission #420692

#TimeUsernameProblemLanguageResultExecution timeMemory
420692nguotKangaroo (CEOI16_kangaroo)C++14
100 / 100
59 ms23048 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0)
#define fori(x,a,b) for (int x=a;x<=b;++x)
#define ford(x,a,b) for (int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define mp make_pair
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);

/*
f[i][j] : so cach tao ra cac nhom thoa man khi xet den i-1 ptu dau tien va con j nhom loai 1;
- loai 1 : gt con dau < gt con thu 2,gt con cuoi < gt con ke no
- loai 2 : bat dau la cs(tuong tu loai 1 nhung bat dau co 2 cach)
- loai 3 : ket thuc la cf(tuong tu loai 1 nhung ket thuc co 2 cach)
*/

const int mod = 1e9 + 7;
const int N = 2e3 + 5;
int f[N][N],n,cs,cf;
void add(int &a,int b)
{
    a+=b;
    if(a>=mod) a-=mod;
}
main()
{
   fasty;
   cin>>n>>cs>>cf;
   if(cs>cf) swap(cs,cf);
   f[1][0] = 1;
   fori(i,1,n) fori(j,0,i-1) if(f[i][j])
   {
       if(i==cf || i==cs)
       {
          add(f[i+1][j],f[i][j]);//ghep cs(cf) voi i+1 thanh nhom loai 1
          if(j) add(f[i+1][j-1],f[i][j]*j%mod);//ghep cs(cf) voi con nho hon no
       }
       else
       {
           if(j>1) add(f[i+1][j-1],f[i][j]*j%mod*(j-1)%mod); //gop 2 nhom loai 1;
           add(f[i+1][j+1],f[i][j]);//i thanh 1 nhom rieng;
           if(cs<i) add(f[i+1][j-1],f[i][j]*j%mod);//gop nhom 2 voi nhom 1 THANH 1 NHOM 2
           if(cf<i) add(f[i+1][j-1],f[i][j]*j%mod);//gop nhom 1 voi nhom 3 THANH 1 NHOM 3
       }
   }
   cout<<f[n][0];
}

Compilation message (stderr)

kangaroo.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...