Submission #543841

# Submission time Handle Problem Language Result Execution time Memory
543841 2022-03-31T13:43:43 Z ala2 Go (COCI18_go) C++14
40 / 100
1000 ms 212 KB
#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 d(int i,int j)
{
    return  abs( 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)
        return -inf;
       // cout<<"    "<<2<<endl;
    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=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 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=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 max(one,tow);
    }

}
signed main()
{
    //int n,k;
    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,0}} );
        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

Compilation message

go.cpp: In function 'long long int f(long long int, long long int, long long int, long long int)':
go.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Execution timed out 1085 ms 212 KB Time limit exceeded
6 Execution timed out 1091 ms 212 KB Time limit exceeded
7 Execution timed out 1049 ms 212 KB Time limit exceeded
8 Execution timed out 1092 ms 212 KB Time limit exceeded
9 Execution timed out 1090 ms 212 KB Time limit exceeded
10 Execution timed out 1065 ms 212 KB Time limit exceeded