Can someone explain me how can i solve the C problem (round 53) because i have no ideea better than O(N^2)? Thx
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Name |
---|
Let B be the set of all arrays of length n in increasing order with entries from the set {1,...,2n-1}.
Let f be a function such that f : A->B and f(x)=y, where y [ i ] = x [ i ] + i, for all i in {0, ..., n-1}.
First let us show that y=f(x) is in B. y is of length n and minimum of y[i](i in {0,...,n-1}) is minimum of x[0] which is 1
and maximum of y[i](i in {0,...,n-1}) is x[n-1]+n-1 which is n+n-1=2n-1. So y is in B.
Let us show that f is bijective.
First let us show that f is injective.
Let x1, x2 be in A and x1!=x2. x1!=x2 implies that there is an i in {0, .., n-1} such that x1[i]!=x2[i] or equivalently
x1[i]+i!=x2[i]+i or f(x1)!=f(x2). So f is injective.
Now let us show f is surjective.
Given y in B and we take x such that x [ i ] = y [ i ] - i, for all i in {0,...,n-1}
we can notice that x is in A(x is of length n and x[i] is in {1,...,n} for al i in {0,...,n-1} because minimum of x[i] is 1 and maximum is n ( don't forget that y is increasing )).
So f is surjective.
Thus f is bijective.
A and B are finite so they have the same number of elements.
We need to find the number of elements in A because the answer we are looking for is the cardinal of the set of arrays A union with the set of all arrays in A in reverse order(let's denote it by R).
Notice that |A|=|R| and that |A union R| = |A|+|R|-|A intersection R|. A intersection R is the set of constant arrays and |A intersection R| is n.
So the answer is 2*|A|-n.
But |A| = |B| and B is the set of all increasing arrays of length n with entries from{1,..,2n-1}.
So the answer is the binomial number. So |A|=|B|=((2n-1)!)/((n!)*((n-1)!)).
Thus the final number is 2*(((2n-1)!)/((n!)*((n-1)!)))-n. Notice that you need modular arithmetic inverse to compute the binomial number.
The computation of the modular inverse can be done in O(log n) by using Fermat theorem or gcd properties.
Why B has numbers from 1 to 2*n -1 ? The problem says only from 1 to n . I didn't understood use of C(2*n-1 , n) .. Any response are welcome . Thanks