답안 #705403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705403 2023-03-04T10:03:53 Z aedmhsn Journey (NOI18_journey) C++17
100 / 100
1999 ms 38272 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<pll>> adj(mxN);

ll solve(int node, int date){
    if(node == 0 && date == 0)
        return 1;
    if(dp[node][date] != -1)
        return dp[node][date];
    ll sum=0;
    bool over=false;
    for(auto [x, y]:adj[node]){
        if(x < node){
            for(int i=0; i<m; i++){
                if(date-y-i >= 0){
                    sum += solve(x, date-y-i);
                    if(sum >= 5e8+1){
                        sum = 5e8+1;
                        over=true;
                        break;
                    }
                }
                else
                    break;
            }
            if(over)
                break;
        }
    }
    return dp[node][date]=sum;
}


int main(){
    boost();
    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 << solve(n-1, i) << " ";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32184 KB Output is correct
2 Correct 13 ms 32200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 32212 KB Output is correct
2 Correct 12 ms 32212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32184 KB Output is correct
2 Correct 13 ms 32200 KB Output is correct
3 Correct 12 ms 32212 KB Output is correct
4 Correct 12 ms 32212 KB Output is correct
5 Correct 15 ms 32340 KB Output is correct
6 Correct 15 ms 32340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 32184 KB Output is correct
2 Correct 13 ms 32200 KB Output is correct
3 Correct 12 ms 32212 KB Output is correct
4 Correct 12 ms 32212 KB Output is correct
5 Correct 15 ms 32340 KB Output is correct
6 Correct 15 ms 32340 KB Output is correct
7 Correct 281 ms 38272 KB Output is correct
8 Correct 1999 ms 35880 KB Output is correct
9 Correct 345 ms 32896 KB Output is correct
10 Correct 208 ms 35124 KB Output is correct