Submission #760044

#TimeUsernameProblemLanguageResultExecution timeMemory
760044ihcekerExam (eJOI20_exam)C++14
39 / 100
80 ms9256 KiB
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; int32_t main(){ int n; cin>>n; int a[n],b[n]; set<int>s; for(int i=0;i<n;i++){ cin>>a[i]; s.insert(a[i]); } for(int i=0;i<n;i++)cin>>b[i]; if(*max_element(b,b+n)==*min_element(b,b+n)){ int c[n]; memset(c,0,sizeof(c)); for(int i=0;i<n;i++){ if(a[i]!=b[i])continue; if(!c[i]){ c[i]=1; } for(int j=i-1;j>=0;j--){ if(a[j]>=b[j])break; c[j]=1; } for(int j=i+1;j<n;j++){ if(a[j]>=b[j])break; c[j]=1; } } int ans=accumulate(c,c+n,0LL); cout<<ans<<endl; return 0; } vector<pair<int,int>>v; for(int i=0;i<n;i++){ if(a[i]>b[i] || !s.count(b[i]))continue; v.pb({b[i],i}); } sort(all(v)); int dp[v.size()],ans=0; for(int i=0;i<(int)v.size();i++){ int mx=0; for(int j=0;j<i;j++){ if(v[i].ss>v[j].ss)mx=max(mx,dp[j]); } dp[i]=mx+1; ans=max(ans,mx+1); } cout<<ans<<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...