# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
543864 | ala2 | Go (COCI18_go) | C++14 | 1111 ms | 320208 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
//#define first first
//#define second second
#define pb push_back
#define B begin()
#define E end()
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
vector < pair< int ,pair<int,int> > >v;
const int inf=1e18;
int n,k;
int dp[101][101][2002][2];
int d(int i,int j)
{
// cout<<" ::: "<<i<< " "<<j<<" "<<fabs( v[i].first-v[j].first )<<endl;
return fabs( v[i].first-v[j].first );
}
int f(int l,int r,int t,int bo)
{
if(l==0&&r==n-1)
return 0;
if(t>2000)
return 0;
if(l<0)
return -inf;
if(r>=n||l>=n)
//return -inf; cout<<" "<<n<<" "<<r<<endl;
if(dp[l][r][t][bo]!=-1)
return dp[l][r][t][bo];
if(bo==0)
{
int one=f(l-1,r,t+d(l-1,l),0)+( (t+d(l-1,l)<v[l-1].second.second)*v[l-1].second.first );
int tow=0;
if(r<n-1) tow=f(l,r+1,t+d(l,r+1),1)+( (t+d(l,r+1)<v[r+1].second.second)*v[r+1].second.first );
return dp[l][r][t][bo]=max(one,tow);
}
if(bo==1)
{
int one=f(l-1,r,t+d(l-1,r),0)+( (t+d(l-1,r)<v[l-1].second.second)*v[l-1].second.first );
int tow=0;
if(r<n-1) tow=f(l,r+1,t+d(r,r+1),1)+( (t+d(r,r+1)<v[r+1].second.second)*v[r+1].second.first );
return dp[l][r][t][bo]=max(one,tow);
}
}
signed main()
{
//int n,k;
FAST
memset(dp,-1,sizeof dp);
map<int,int>m;
cin>>n>>k>>n;
for(int i=0;i<n;i++)
{
int x,y,z;
cin>>x>>y>>z;
m[x]=1;
v.pb( {x,{y,z}} );
}
if(m[k]==0)
{
v.pb( {k,{0,1}} );
n++;
}
sort(v.B,v.E);
for(int i=0;i<n;i++)
{
if(v[i].first==k)
{
cout<<f(i,i,0,0)<<endl;
}
}
}
//111
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |