Submission #329797

#TimeUsernameProblemLanguageResultExecution timeMemory
329797JiratQCryptography (NOI20_crypto)C++14
14 / 100
1096 ms32852 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int dp[300010]; int fac(int n){ if(dp[n]!=0) return dp[n]; if(n==0) return 1; return dp[n]=(fac(n-1)%1000000007*n) %1000000007; } 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("%lld",&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;*/ unordered_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)%1000000007 * fac(n-1-i))%1000000007; } cout << ans+1; } //

Compilation message (stderr)

Crypto.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      |      ^
Crypto.cpp: In function 'int main()':
Crypto.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |         scanf("%lld",&k);
      |         ~~~~~^~~~~~~~~~~
#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...