Submission #948347

#TimeUsernameProblemLanguageResultExecution timeMemory
948347LilypadCryptography (NOI20_crypto)C++14
48 / 100
1095 ms7312 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll,ll> #define pb push_back #define fi first #define se second const ll N = 3e5+3; const ll MOD = 1e9+7; ll a[N],b[N],fac[N]; ll n,tmp,ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; fac[0] = 1; for(int i=1; i<=n; i++) { cin >> a[i]; b[i] = a[i]; fac[i] = fac[i-1] * i; fac[i] %= MOD; } // sort(b+1,b+n+1); // for(int i=1; i<=n; i++) { // mp[b[i]] = i; // } // for(int i=1; i<=n; i++) a[i] = mp[a[i]]; for(int i=1; i<=n; i++) { tmp = 0; for(int j=i+1; j<=n; j++) { if(a[i] > a[j]) tmp++; } ans += (fac[n-i] * tmp) % MOD; ans %= MOD; } cout << (ans + 1) % MOD << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...