Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #define M 1000000007
- #define N 1000001
- using namespace std;
- int v[N];
- #define DIM 10000
- char buff[DIM];
- int poz=0;
- void citeste(int &numar)
- {
- numar = 0;
- //cat timp caracterul din buffer nu e cifra ignor
- while (buff[poz] < '0' || buff[poz] > '9')
- //daca am "golit" bufferul atunci il umplu
- if (++poz == DIM)
- fread(buff,1,DIM,stdin),poz=0;
- //cat timp dau de o cifra recalculez numarul
- while ('0'<=buff[poz] && buff[poz]<='9')
- {
- numar = numar*10 + buff[poz] - '0';
- if (++poz == DIM)
- fread(buff,1,DIM,stdin),poz=0;
- }
- }
- int main()
- {
- int n;
- cin>>n;
- for(int i=0;i<n;++i)
- citeste(v[i]);
- sort(v,v+n);
- int fact=1;
- for(int i=1;i<=v[0];++i)
- fact=(int)(1LL*fact*i%M);
- int p=fact;
- for(int i=1;i<n;++i)
- {
- if(v[i]==v[i-1])
- p=(int)(1LL*p*fact%M);
- else
- {
- for(int j=v[i-1]+1;j<=v[i];++j)
- fact=(int)(1LL*fact*j%M);
- p=(int)(1LL*p*fact%M);
- }
- }
- cout<<p<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement