답안 #947514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947514 2024-03-16T10:26:14 Z devkudawla Journey (NOI18_journey) C++17
100 / 100
74 ms 36176 KB
#include <bits/stdc++.h>
using namespace std;
int n, m, h;
const int N = 10010, M = 410;
int dp[N + 1][M + 1];
int prefix[N + 1][M + 1];
vector<vector<pair<int, int>>> graph(N + 1);
void solve(bool testCases = true) {
    int T = 1;
    if (testCases) cin >> T;
    while (T--) {
        cin >> n >> m >> h;
        memset(dp, 0, sizeof(dp));
        memset(prefix, 0, sizeof(prefix));
        dp[0][0] = 1;
        prefix[0][0] = dp[0][0];
        for (int j = 1; j < m; j++) {
            prefix[0][j] += prefix[0][j - 1] + dp[0][j];
            prefix[0][j] = min(prefix[0][j], 500000001);
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < h; j++) {
                int a, b;
                cin >> a >> b;
                if (i >= a) {
                    continue;
                }
                graph[a].push_back({i, b});
            }
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (auto [child, weight] : graph[i]) {
                    if (j - weight >= 0) {
                        dp[i][j] += prefix[child][j - weight];
                        dp[i][j] = min(dp[i][j], 500000001);
                    }
                }
            }
            prefix[i][0] = dp[i][0];
            for (int j = 1; j < m; j++) {
                prefix[i][j] += prefix[i][j - 1] + dp[i][j];
                prefix[i][j] = min(prefix[i][j], 500000001);
            }
        }
        for (int i = 0; i < m; i++) {
            cout << dp[n - 1][i];
            cout << " ";
        }
        cout << "\n";
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve(false);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 32856 KB Output is correct
2 Correct 17 ms 32864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 32856 KB Output is correct
2 Correct 13 ms 32848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 32856 KB Output is correct
2 Correct 17 ms 32864 KB Output is correct
3 Correct 13 ms 32856 KB Output is correct
4 Correct 13 ms 32848 KB Output is correct
5 Correct 13 ms 32856 KB Output is correct
6 Correct 13 ms 32860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 32856 KB Output is correct
2 Correct 17 ms 32864 KB Output is correct
3 Correct 13 ms 32856 KB Output is correct
4 Correct 13 ms 32848 KB Output is correct
5 Correct 13 ms 32856 KB Output is correct
6 Correct 13 ms 32860 KB Output is correct
7 Correct 49 ms 36176 KB Output is correct
8 Correct 68 ms 34912 KB Output is correct
9 Correct 22 ms 33116 KB Output is correct
10 Correct 74 ms 34644 KB Output is correct