# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329790 | JiratQ | Cryptography (NOI20_crypto) | C++14 | 1100 ms | 17112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int dp[30010];
int fac(int n){
if(dp[n]!=0) return dp[n];
if(n==0) return 1;
return dp[n]=(fac(n-1)*n) %1000000009;
}
main(){
//ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
int n;
cin >> n;
vector<int> vec;
for(int i=0;i<n;i++){
int k;
scanf("%d",&k);
vec.emplace_back(k);
}
vector<int> v=vec;
sort(v.begin(),v.end());
unordered_map<int,int> mapp;
int cnt=1;
for(int i=0;i<n;i++){
mapp[v[i]]=cnt;
cnt++;
}
for(int i=0;i<n;i++){
vec[i]=mapp[vec[i]];
}
/*for(int i=0;i<n;i++){
cout << vec[i] << " ";
}
cout << endl;*/
map<int,int> m;
int ans=0;
for(int i=0;i<n;i++){
int use=vec[i];
int c=0;
for(auto& k:m){
if(use>k.first){
c++;
}
}
m[use]=1;
ans += ((use-1-c) * fac(n-1-i))%1000000009;
}
cout << ans+1;
}
//
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |