//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 1e4+100;
const int MAXM = 4e2+100;
const ll MAX = 5e8+1;
int N, M, H;
vector<pii> g[MAXN];
ll dp[MAXM][MAXN];
void solve(){
cin >> N >> M >> H;
rep(i, 0, N - 1){
rep(h, 0, H){
int j, w;
cin >> j >> w;
if(j > i)
g[i].pb({j, w});
}
}
dp[0][0] = 1;
rep(v, 0, N - 1){
rep(m, 0, M){
dp[m + 1][v] += dp[m][v];
}
for(auto [u, w] : g[v]){
per(m, M, w){
dp[m][u] = min(MAX, dp[m][u] + dp[m - w][v]);
}
}
}
rep(m, 0, M){
cout << dp[m][N - 1] << " ";
}
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
solve();
return 0;
}
Compilation message
journey.cpp: In function 'void solve()':
journey.cpp:42:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for(auto [u, w] : g[v]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
2 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
1132 KB |
Output is correct |
6 |
Correct |
2 ms |
1132 KB |
Output is correct |
7 |
Correct |
50 ms |
5996 KB |
Output is correct |
8 |
Correct |
69 ms |
10348 KB |
Output is correct |
9 |
Correct |
16 ms |
4972 KB |
Output is correct |
10 |
Correct |
80 ms |
6124 KB |
Output is correct |