# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586461 | hibiki | Journey (NOI18_journey) | C++11 | 3 ms | 4564 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define MX 500000001
#define pb push_back
#define f first
#define s second
int n,m,h;
vector<pair<int,int> > v[10005];
int dp[10005][105];
int ind[10005];
int main()
{
scanf("%d %d %d",&n,&m,&h);
for(int i = 0; i < n - 1; i++)
{
for(int j = 0; j < h; j++)
{
int a,b;
scanf("%d %d",&a,&b);
if(i >= a) continue;
v[i].pb({a,b});
ind[a]++;
}
}
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
queue<int> q;
q.push(0);
while(!q.empty())
{
int nw = q.front();
q.pop();
if(nw != 0)
for(int i = 1; i < m; i++)
{
dp[nw][i] += dp[nw][i - 1];
if(dp[nw][i] > MX)
dp[nw][i] = MX;
}
for(auto go: v[nw])
{
ind[go.f]--;
if(ind[go.f] == 0)
q.push(go.f);
for(int i = 0; i + go.s < m; i++)
{
dp[go.f][i + go.s] += dp[nw][i];
if(dp[go.f][i + go.s] > MX)
dp[go.f][i + go.s] = MX;
}
}
}
for(int i = 0; i < m; i++)
printf("%d ",dp[n - 1][i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |