답안 #660424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660424 2022-11-21T20:06:14 Z Ahmed57 Go (COCI18_go) C++14
100 / 100
113 ms 163356 KB
#include <bits/stdc++.h>

using namespace std;
vector<vector<int>> v;
int m,n,k;
int dp[102][102][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;
        }
    }
    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]
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 163156 KB Output is correct
2 Correct 61 ms 163200 KB Output is correct
3 Correct 62 ms 163240 KB Output is correct
4 Correct 60 ms 163212 KB Output is correct
5 Correct 80 ms 163196 KB Output is correct
6 Correct 67 ms 163204 KB Output is correct
7 Correct 101 ms 163168 KB Output is correct
8 Correct 103 ms 163356 KB Output is correct
9 Correct 113 ms 163248 KB Output is correct
10 Correct 104 ms 163196 KB Output is correct