이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
/**
|||||||||| ||||| ||||| ||||||||||
||||||||||||| ||||| ||||| |||||
|||| |||||| ||||| ||||| |||||
||||||||||||||||| ||||||||||||||| ||||||||||
||||||||||||||||||| ||||||||||||||| |||||
||||| ||||| ||||| ||||| |||||
||||| ||||| ||||| ||||| ||||||||||
AHMED;HASSAN;SAEED;
*/
using namespace std;
vector<pair<int,int> >vls;
vector<int>v;
map<int,pair<int,pair<int,int> > >dp[150000];
bool comp(pair<int,int>a,pair<int,int>b){
if(a.first==b.first)
return a.second<b.second;
return a.first<b.first;
}
int mp(int key){
vector<pair<int,int> >::iterator it=lower_bound(vls.begin(),vls.end(),make_pair(key,-1),comp);
if(it==vls.end()||((it->first)!=key))
return 0;
return it->second;
}
int n,k;
int slv(int l,int r){
if(dp[l][r].first)
return dp[l][r].first;
int ret=1;
for(int i=l+1;i<r&&(i-l)<=k+5;i++){
int mpvl=mp(v[r]-(v[i]-v[l]));
if(mpvl>i+1){
int ret2=1+slv(i,mpvl-1);
///cout<<'#'<<i<<' '<<mp(v[r]-(v[i]-v[l]))-1<<'\n';
if(ret2>ret){
ret=ret2;
dp[l][r].second={i,mpvl-1};
}
break;
}
}
return dp[l][r].first=ret;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k;
n+=k;
vls=vector<pair<int,int> >(n*k+5);
int cr=0;
v=vector<int>(n);
for(int i=0;i<n;i++){
cin>>v[i];
for(int j=0;j<k;j++)
vls[cr++]={v[i],i+1};
}
int ans=0;
int l,r;
for(int i=0;i<=k;i++){
for(int j=n-1;j>=n-k-1&&(i+n-1-j)<=k;j--){
int ret=slv(i,j);
if(ret>ans){
ans=ret;
l=i,r=j;
}
}
}
vector<int>v2(n-k);
int cnt=0;
int tol=0,tor=n-k-1;
while(cnt<n-k){
v2[tol]=v[l],v2[tor]=v[r];
int nl=dp[l][r].second.first,nr=dp[l][r].second.second;
l=nl,r=nr;
cnt+=2;
tol++; tor--;
}
for(int i=0;i<n-k;i++)
cout<<v2[i]<<' ';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.cpp: In function 'int32_t main()':
tabletennis.cpp:84:20: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | v2[tol]=v[l],v2[tor]=v[r];
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |