UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207847#3711. Heavenly Altitudes_Alexande_10057ms9104kbC++112.0kb2024-08-01 08:49:212024-08-01 12:36:42

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define fir first
#define sec second
#define mkp make_pair 
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

char _c; bool _f; template < class type > inline void read ( type &x ) {
	_f = 0, x = 0;
	while ( _c = getchar (), !isdigit ( _c ) ) if ( _c == '-' ) _f = 1;
	while ( isdigit ( _c ) ) x = x * 10 + _c - '0', _c = getchar (); if ( _f ) { x = -x; }
}

template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }

const int N = 1e6 + 5;
const int mod = 1e9 + 7;

int n, m, ans = 1;
int a[N], fac[N];

void init () {
  fac[0] = 1;
  for ( int i = 1; i <= n; i ++ ) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
}

int fast_pow ( int a, int b ) {
  int res = 1;
  while ( b ) {
    if ( b & 1 ) {
      res = res * a;
      res %= mod;
    }
    b >>= 1;
    a = a * a;
    a %= mod;
  }
  return res;
}

int C ( int n, int m ) {
  if ( n < m ) {
    return 0;
  }
  return fac[n] * fast_pow ( fac[m], mod - 2 ) % mod * fast_pow ( fac[n - m], mod - 2 ) % mod;
}

void Solve () {
  cin >> n >> m;
  for ( int i = 1; i <= m; i ++ ) {
    cin >> a[i];
  }
  init ();
  sort ( a + 1, a + 1 + m, [] ( int x, int y ) { return x > y; } );
  int block = n / m, res = 0;
  for ( int i = 1; i <= m; i ++ ) {
    ans *= C ( n - a[i] - res, block - 1 ) % mod;
    ans %= mod;
    // cout << C ( n - a[i] - res, block - 1 ) << '\n';
    res += block;
  }
  cout << ans;
}

signed main () {
#ifdef judge
  freopen ( "Code.in", "r", stdin );
  freopen ( "Code.out", "w", stdout );
  freopen ( "Code.err", "w", stderr );
#endif
  Solve ();
  return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1216kb

input:

9 3
1 3 4

output:

30

result:

ok 1 number(s): "30"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1220kb

input:

10 5
1 2 3 4 6

output:

96

result:

ok 1 number(s): "96"

Test #3:

score: 10
Accepted
time: 1ms
memory: 1228kb

input:

1000 125
1 2 4 6 7 8 10 12 13 16 19 24 25 26 28 29 30 31 39 40 41 46 49 52 55 64 65 67 68 77 78 81 8...

output:

131515409

result:

ok 1 number(s): "131515409"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1224kb

input:

999 111
1 2 6 7 10 12 13 15 19 26 29 32 33 52 53 54 57 58 59 60 69 73 78 87 91 101 103 105 106 110 1...

output:

172899290

result:

ok 1 number(s): "172899290"

Test #5:

score: 10
Accepted
time: 2ms
memory: 2008kb

input:

100000 1250
1 4 13 19 26 33 46 53 68 72 78 100 104 115 116 126 129 131 142 150 156 157 160 167 197 2...

output:

821794520

result:

ok 1 number(s): "821794520"

Test #6:

score: 10
Accepted
time: 7ms
memory: 2088kb

input:

99999 11111
1 2 4 5 9 10 11 12 13 14 15 16 17 19 20 21 22 23 25 27 29 31 32 33 34 35 36 39 41 42 43 ...

output:

941657016

result:

ok 1 number(s): "941657016"

Test #7:

score: 10
Accepted
time: 7ms
memory: 9036kb

input:

1000000 1000
1 200 304 310 404 584 622 831 1056 1160 1948 1984 2027 2137 2216 2434 2452 2488 2667 27...

output:

109815619

result:

ok 1 number(s): "109815619"

Test #8:

score: 10
Accepted
time: 4ms
memory: 9104kb

input:

1000000 10000
1 6 8 13 15 28 44 51 56 72 73 83 97 99 105 113 126 130 136 177 183 184 213 218 265 288...

output:

780311646

result:

ok 1 number(s): "780311646"

Test #9:

score: 10
Accepted
time: 9ms
memory: 9024kb

input:

1000000 100
1 742 1563 4179 8008 8716 11385 16121 16656 17170 18699 24004 29401 31368 35296 35580 45...

output:

338576884

result:

ok 1 number(s): "338576884"

Test #10:

score: 10
Accepted
time: 27ms
memory: 8480kb

input:

900000 30000
1 3 6 7 9 10 18 22 24 29 30 32 33 34 39 44 46 54 55 62 63 64 75 78 84 90 93 95 96 99 10...

output:

507088503

result:

ok 1 number(s): "507088503"