Submission #840151

#TimeUsernameProblemLanguageResultExecution timeMemory
840151TsotneSVExam (eJOI20_exam)C++17
0 / 100
284 ms4968 KiB
#pragma gcc diagnostic "-std=c++1z" #include <bits/stdc++.h> using namespace std; /* /\_/\ (= ._.) / > \> */ //#define int long long #define fi first #define se second #define pb push_back #define ins insert #define mp make_pair #define endl "\n" #define sz(x) (int) (x).size() #define deb(x) cout<<(x)<<endl #define all(x) (x).begin(),(x).end() #define dbg(x) cerr<<#x<<" "<<x<<endl typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; const ll inf=1e9; const ll INF=1e18; const ll mod=998244353; const ll MOD=1e9+7; const ll MAXN=2e5+5; int n,A[5005],B[5005]; int dp[5005][2]; map<int,int> freq[5005]; void solve(){ cin>>n; for(int i=1;i<=n;i++) cin>>A[i]; for(int i=1;i<=n;i++) { cin>>B[i]; freq[i][B[i]] = freq[i-1][B[i]] + 1; } dp[n+1][0] = dp[n+1][1] = 0; for(int i=n;i>0;i--) { dp[i][0] = max(dp[i+1][0],dp[i+1][1]) + (A[i] == B[i]); int mx = 0; for(int j=i;j<=n;j++) { mx = max(mx,A[j]); dp[i][1] = max(dp[i][1],freq[j][mx] - freq[i-1][mx] + max(dp[j+1][0],dp[j+1][1])); } } deb(max(dp[1][0],dp[1][1])); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); int tt=1; // cin>>tt; while(tt--){ solve(); } }

Compilation message (stderr)

exam.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
    1 | #pragma gcc diagnostic "-std=c++1z"
      |
#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...