답안 #660422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660422 2022-11-21T19:36:24 Z Ahmed57 Go (COCI18_go) C++14
0 / 100
225 ms 324404 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)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>=0){
        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;
    for(int i = 0;i<m;i++){
        long long a,b,c;cin>>a>>b>>c;
        v.push_back({a,b,c});
        if(a>=m&&u==m){
            u = i;
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(u-1,u,1,0);
}

Compilation message

go.cpp: In function 'int main()':
go.cpp:36:22: warning: narrowing conversion of 'a' from 'long long int' to 'int' [-Wnarrowing]
   36 |         v.push_back({a,b,c});
      |                      ^
go.cpp:36:22: warning: narrowing conversion of 'a' from 'long long int' to 'int' [-Wnarrowing]
go.cpp:36:24: warning: narrowing conversion of 'b' from 'long long int' to 'int' [-Wnarrowing]
   36 |         v.push_back({a,b,c});
      |                        ^
go.cpp:36:24: warning: narrowing conversion of 'b' from 'long long int' to 'int' [-Wnarrowing]
go.cpp:36:26: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
   36 |         v.push_back({a,b,c});
      |                          ^
go.cpp:36:26: warning: narrowing conversion of 'c' from 'long long int' to 'int' [-Wnarrowing]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 160068 KB Output isn't correct
2 Incorrect 60 ms 160060 KB Output isn't correct
3 Incorrect 61 ms 159980 KB Output isn't correct
4 Incorrect 69 ms 159948 KB Output isn't correct
5 Runtime error 188 ms 324260 KB Execution killed with signal 11
6 Runtime error 188 ms 324404 KB Execution killed with signal 11
7 Runtime error 188 ms 324296 KB Execution killed with signal 11
8 Runtime error 225 ms 324340 KB Execution killed with signal 11
9 Runtime error 202 ms 324392 KB Execution killed with signal 11
10 Runtime error 197 ms 324404 KB Execution killed with signal 11