이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=5000+5,mod=1e9+7;
int t,mx[N][N],b[N],a[N],dp[N],ans,n;
map<int,vector<int> > c;
bool ok(int x,int y) {
if(mx[min(x,y)][max(x,y)] == a[x]) return 1;
return 0;
}
main(){
cin>>n;
for(int i=1;i<=n;i++) {
cin >> a[i];
}
int f = 0;
for(int i=1;i<=n;i++){
cin >> b[i];
if(i && b[i]!=b[i-1]) f = 1;
}
for(int i=1;i<=n;i++) {
for(int j=i;j<=n;j++) {
mx[i][j] = max(mx[i][j-1],a[j]);
}
}
int ans = 0;
if(!f) {
for(int i=1;i<=n;i++){
int j = i - 1,F = 0;
while(j<n && a[j+1] <= b[1]) {
j ++;
if(b[1]==a[j]) F = 1;
}
if(F) ans += j - i + 1;
i = max(i,j);
}
cout<<ans;
return 0;
}
for(int i=1;i<=n;i++){
c[a[i]].push_back(i);
}
for(int i=1;i<=n;i++) {
for(int j=c[b[i]].size() - 1;j>=0;j--) {
int ind = c[b[i]][j];
dp[ind] = dp[ind] + ok(ind,i);
}
for(int j=1;j<=n;j++) {
dp[j] = max(dp[j],dp[j-1]);
ans = max(dp[j],ans);
} //cout<<endl;
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
exam.cpp:13:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main(){
| ^~~~| # | 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... |