Submission #660423

# Submission time Handle Problem Language Result Execution time Memory
660423 2022-11-21T20:04:56 Z Ahmed57 Go (COCI18_go) C++14
0 / 100
119 ms 160116 KB
#include <bits/stdc++.h>

using namespace std;
vector<vector<int>> v;
int m,n,k;
int dp[101][101][2001][2];
long long solve(int l,int r,int ti,int tu){
    if(ti>2000)return 0;
    if(l==0&&r==m+1)return 0;
    if(dp[l][r][ti][tu]!=-1)return dp[l][r][ti][tu];
    int ind = 0;
    if(l+1==r){
        ind = k;
    }else {
        if(tu==0){
            ind = v[l+1][0];
        }else{
            ind = v[r-1][0];
        }
    }
    long long c1 = 0;
    if(l>=1){
        int ne = ti+abs(v[l][0]-ind);
        c1 = max(c1,solve(l-1,r,ne,0)+(ne<=v[l][2]?v[l][1]:0));
    }if(r<=m){
        int ne = ti+abs(v[r][0]-ind);
        c1 = max(c1,solve(l,r+1,ne,1)+(ne<=v[r][2]?v[r][1]:0));
    }
    return dp[l][r][ti][tu] = c1;
}
int main(){
    cin>>n>>k>>m;
    int u = m+1;
    v.push_back({0});
    for(int i = 1;i<=m;i++){
        long long a,b,c;cin>>a>>b>>c;
        v.push_back({a,b,c});
        if(a>=k&&u==m+1){
            u = i;
        }
    }
    cout<<u<<"\n";
    memset(dp,-1,sizeof dp);
    cout<<solve(u-1,u,1,0);
}

Compilation message

go.cpp: In function 'int main()':
go.cpp:37:22: warning: narrowing conversion of 'a' from 'long long int' to 'int' [-Wnarrowing]
   37 |         v.push_back({a,b,c});
      |                      ^
go.cpp:37:22: warning: narrowing conversion of 'a' from 'long long int' to 'int' [-Wnarrowing]
go.cpp:37:24: warning: narrowing conversion of 'b' from 'long long int' to 'int' [-Wnarrowing]
   37 |         v.push_back({a,b,c});
      |                        ^
go.cpp:37:24: warning: narrowing conversion of 'b' from 'long long int' to 'int' [-Wnarrowing]
go.cpp:37:26: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   37 |         v.push_back({a,b,c});
      |                          ^
go.cpp:37:26: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 160064 KB Output isn't correct
2 Incorrect 60 ms 159948 KB Output isn't correct
3 Incorrect 60 ms 160056 KB Output isn't correct
4 Incorrect 61 ms 160028 KB Output isn't correct
5 Incorrect 79 ms 160116 KB Output isn't correct
6 Incorrect 70 ms 159956 KB Output isn't correct
7 Incorrect 97 ms 159968 KB Output isn't correct
8 Incorrect 111 ms 160076 KB Output isn't correct
9 Incorrect 112 ms 160064 KB Output isn't correct
10 Incorrect 119 ms 160080 KB Output isn't correct