이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PB push_back
#define F first
#define S second
const int INF=1e9;
const long long LINF=1e18;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
void setIO()
{
FAST_IO;
}
void setIO (string s) {
setIO();
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int N=5e3+10, L=28;
int n, a[N], b[N], st[N][L], dp[N][N];
void build()
{
FOR(i, 1, L)
{
for(int j=1; j+(1<<i)-1<=n; j++){
st[j][i]=max(st[j][i-1], st[j+(1<<(i-1))][i-1]);
}
}
}
int get(int l, int r)
{
int ln=r-l+1;
int k=0;
while((1<<(k+1))<=ln){
k++;
}
return max(st[l][k], st[r-(1<<k)+1][k]);
}
int main()
{
setIO();
cin >> n;
FOR(i, 0, n)
{
cin >> a[i+1];
st[i+1][0]=a[i+1];
}
FOR(i, 0, n) cin >> b[i+1];
build();
FOR(i, 1, n+1)
{
FOR(j, 1, n+1)
{
if(a[i]==b[j]){
int mx=get(min(i, j), max(i, j));
if(mx==a[i]){
dp[i][j]=1;
dp[i][j]+=max(dp[i][j-1], dp[i-1][j-1]);
}
else{
dp[i][j]=max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]);
}
}
else{
dp[i][j]=max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]);
}
}
}
cout << dp[n][n];
}
컴파일 시 표준 에러 (stderr) 메시지
exam.cpp: In function 'void setIO(std::string)':
exam.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exam.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |