이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
}
컴파일 시 표준 에러 (stderr) 메시지
exam.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
1 | #pragma gcc diagnostic "-std=c++1z"
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |