Submission #705397

# Submission time Handle Problem Language Result Execution time Memory
705397 2023-03-04T09:57:32 Z aedmhsn Journey (NOI18_journey) C++17
43 / 100
98 ms 32276 KB
#include <bits/stdc++.h>
using namespace std;
 
 
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a)) 
 
 
#define boost() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);

const int mxN=1e4+5;

ll n, m, h, dp[mxN][405];
vector <vector<pii>> adj(mxN);

ll solve(int node, int date){
    if(date < 0)
        return 0;
    if(node == 0 && date == 0)
        return 1;
    if(dp[node][date] != -1)
        return dp[node][date];
    ll sum=0;
    for(auto [x, y]:adj[node]){
        if(x < node){
            for(int i=0; i<m; i++){
                sum += solve(x, date-y-i);
            }
        }
    }
    return dp[node][date]=sum;
}


int main(){
    ms(dp, -1);
    cin >> n >> m >> h;
    for(int i=0; i<n-1; i++){
        for(int j=0; j<h; j++){
            int x, y;
            cin >> x >> y;
            adj[x].push_back({i, y});
        }
    }
    for(int i=0; i<=m-1; i++)
        cout << min(solve(n-1, i), (ll)5e8+1) << " ";
}

# Verdict Execution time Memory Grader output
1 Correct 14 ms 32148 KB Output is correct
2 Correct 14 ms 32156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 32212 KB Output is correct
2 Correct 13 ms 32268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32148 KB Output is correct
2 Correct 14 ms 32156 KB Output is correct
3 Correct 13 ms 32212 KB Output is correct
4 Correct 13 ms 32268 KB Output is correct
5 Incorrect 98 ms 32276 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32148 KB Output is correct
2 Correct 14 ms 32156 KB Output is correct
3 Correct 13 ms 32212 KB Output is correct
4 Correct 13 ms 32268 KB Output is correct
5 Incorrect 98 ms 32276 KB Output isn't correct
6 Halted 0 ms 0 KB -