Submission #668393

#TimeUsernameProblemLanguageResultExecution timeMemory
668393600MihneaJourney (NOI18_journey)C++17
100 / 100
189 ms5188 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 500000001; struct T { int nxt; int stay; }; void addup(int &a, int b) { a = min(INF, a + b); } int main() { #ifdef ONPC freopen ("input.txt", "r", stdin); #endif // ONPC #ifndef ONPC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif // ONPC int n, m, h; cin >> n >> m >> h; vector<vector<T>> g(n); vector<int> sol(m); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < h; j++) { int nxt, stay; cin >> nxt >> stay; if (nxt > i) { g[i].push_back({nxt, stay}); } } } vector<vector<int>> dp(n, vector<int> (m + 1, 0)); dp[0][0] = 1; dp[0][1] = -1; for (int i = 0; i < n; i++) { for (int cur = 0; cur <= m; cur++) { if (cur - 1 >= 0) { addup(dp[i][cur], dp[i][cur - 1]); } for (auto &it : g[i]) { if (cur + it.stay <= m) { addup(dp[it.nxt][cur + it.stay], dp[i][cur]); } } } } for (int i = 0; i < m; i++) { cout << dp[n - 1][i] << " "; } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...