#include <bits/stdc++.h>
using namespace std;
long long n,m,h;
long long f[10001][401];
vector <pair<long long,long long> >v[10001];
void solve()
{
for(long long start=0;start<n-1;start++)
{
for(long long i=0;i<v[start].size();i++)
{
if(v[start][i].first>start)
{
long long sum=0;
for(long long j=0;j<m-v[start][i].second;j++)
{
sum=min(sum+f[start][j],(long long)500000001);
f[v[start][i].first][j+v[start][i].second]=min(f[v[start][i].first][j+v[start][i].second]+sum,(long long)500000001);
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> h;
long long j,k;
for(long long i=0;i<n-1;i++)
{
for(long long t=0;t<h;t++)
{
cin >> j >> k;
v[i].push_back(make_pair(j,k));
//v[j].push_back(make_pair(i,k));
}
}
f[0][0]=1;
solve();
for(long long i=0;i<m;i++)
{
cout << min((long long)500000001,f[n-1][i])<<' ';
}
return 0;
}
Compilation message
journey.cpp: In function 'void solve()':
journey.cpp:11:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i=0;i<v[start].size();i++)
~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
1016 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
1016 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
112 ms |
37976 KB |
Output is correct |
8 |
Correct |
99 ms |
23160 KB |
Output is correct |
9 |
Correct |
29 ms |
3576 KB |
Output is correct |
10 |
Correct |
164 ms |
5368 KB |
Output is correct |