fork download
  1. //...START BY DOING WHAT IS NECESSARY, THEN WHAT IS POSSIBLE AND SUDDENLY YOU ARE DOING THE IMPOSSIBLE...
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define FAST_FURIER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  5. #define pb push_back
  6. #define mk make_pair
  7. #define rep(i,a,N) for(ll i=a;i<N;i++)
  8. #define rrep(i,a,N) for(ll i=a;i>N;i--)
  9. typedef long long ll;
  10. #define M 1000000007
  11. bool comp(int x,int y)
  12. {
  13. return x > y;
  14. }
  15.  
  16.  
  17. /*..............................code starts here........................*/
  18. // S is the courage to continue that counts.
  19. ll m,n,k,x,post,s,t;
  20. ll factorial[1002];
  21. void fac(){
  22. factorial[1] = 1;
  23. factorial[0] = 1;
  24. rep(i,2,1002){
  25. factorial[i] = (factorial[i-1] * i)%M;
  26. }
  27. }
  28. ll power(ll no,ll p)
  29. {
  30. if(p == 1)
  31. return no;
  32. if(p == 0)
  33. return 1;
  34. ll q = power(no,p/2);
  35. q = (q*q)%M;
  36. if(p % 2 != 0)
  37. q = (q*no)%M;
  38. return q;
  39. }
  40. vector<int>vec;
  41. void binsearch(){
  42. int left = 0,right = n;
  43. while(left < right){
  44. int middle = int((left+right)/2);
  45. if(middle <= post){
  46. left = middle+1;
  47. }
  48. else right = middle;
  49. if(middle != n) vec.pb(middle);
  50. }
  51. rep(i,0,vec.size()){
  52. if(vec[i] < post) ++s;
  53. else if(vec[i] > post) ++t;
  54. }
  55. }
  56. int main() {
  57. FAST_FURIER;
  58. int t=1;
  59. //cin >> t;
  60. // string a,b;
  61. fac();
  62. while(t--)
  63. {
  64. cin >> n >> x >> post;
  65. binsearch();
  66. //formula = (n-(1+t+s))! *((x-1)! * (n-x)!)/(x-1-s)!*(n-x-t)!
  67. if(s > x-1 or t > n-x) cout << 0 << endl;
  68. else{
  69. ll a = factorial[n-1-t-s], b = factorial[x-1], c = factorial[n-x];
  70. ll d = power(factorial[x-1-s],M-2)%M, e = power(factorial[n-x-t],M-2)%M;
  71. a = ((a*b)%M*c)%M;
  72. d = (d*e)%M;
  73. a = (a*d)%M;
  74. cout << a << endl;
  75. }
  76. }
  77. }
  78.  
  79.  
  80.  
  81. // Author : shivam_123
  82.  
  83. // g++ -std=c++17
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
0