Submission #570243

#TimeUsernameProblemLanguageResultExecution timeMemory
570243XJP12Mountains (NOI20_mountains)C++14
79 / 100
2069 ms2764 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ ll n; cin>>n; vector<ll> v(n); bool ban=true; bool ban2=true; ll one=0; ll zero=0; vector<ll> h(100,0); vector<ll> htwo(100,0); for(ll i=0; i<n; i++){ cin>>v[i]; if(v[i]==1){ one++; } if(v[i]==0){ zero++; } if(i>0 && ban==true){ if(v[i]<v[i-1]) ban=false; } if(v[i]>100){ ban2=false; }else{ h[v[i]]++; } } if(ban==true){ cout<<"0"<<endl; return 0; } if(one+zero==n){ // cout<<"hello"<<endl; ll zerotwo=0; ll ans=0; for(int i=0; i<n; i++){ if(v[i]==0){ zerotwo++; continue; }else{ ans+=zerotwo*(zero-zerotwo); } } cout<<ans<<endl; return 0; } if(ban2==true){ ll totall; ll totalr; ll ans=0; for(ll i=0; i<n; i++){ totall=0; totalr=0; htwo[v[i]]++; // cout<<"numero actual "<<v[i]<<endl; for(ll j=0; j<v[i]; j++){ totall+=htwo[j]; totalr+=(h[j]-htwo[j]); // cout<<totall<<totalr<<endl; } ans+=(totall*totalr); } cout<<ans<<endl; return 0; } ll cont=1; ll ans=0; ll a,b; while(cont<n-1){ a=0; b=0; for(ll i=0; i<cont; i++){ if(v[i]<v[cont]) a++; } for(ll i=cont+1; i<n; i++){ if(v[i]<v[cont]) b++; } ans+=a*b; cont++; } cout<<ans<<endl; return 0; }
#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...