# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95563 | oolimry | Journey (NOI18_journey) | C++14 | 253 ms | 40008 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;
typedef long long l;
typedef pair<l, l> ii;
///stores edges where it comes from, not goes to
vector<ii> adj[10005];
l e;
l memo[10005][405];
///isWaiting 0 - false, 1- true
l dp(l city, l nights){
if(nights < 0){
return 0;
}
if(city == 0 && nights == 0){
return 1;
}
if(memo[city][nights] != -1){
return memo[city][nights];
}
l ways = 0;
for(l i = 0;i < adj[city].size();i++){
l neigh = adj[city][i].first;
l time = adj[city][i].second;
if(neigh < city){
ways += dp(neigh, nights - time);
}
if(ways > 500000001){
return 500000001;
}
}
if(city != e){
ways += dp(city, nights - 1);
}
//printf("%d %d %d\n",city,nights,ways);
if(ways > 500000001){
return 500000001;
}
memo[city][nights] = ways;
return ways;
}
int main()
{
//freopen("i.txt","r",stdin);
l n, m, h;
scanf("%lld %lld %lld",&n,&m,&h);
e = n - 1;
for(int i = 0;i < n - 1;i++){
for(int j = 0;j < h;j++){
l a, b;
scanf("%lld %lld", &a, &b);
adj[a].push_back(ii(i,b));
}
}
memo[0][0] = 1;
for(int i = 0;i < 10003;i++){
for(int j = 0 ;j < 403;j++){
memo[i][j] = -1;
}
}
for(int i = 0;i < n;i++){
for(int j = 0;j < adj[i].size();j++){
//printf("%lld %lld | ",adj[i][j].first,adj[i][j].second);
}
//printf("\n");
}
for(int i = 0;i < m;i++){
printf("%lld ",dp(n-1, i));
//printf("\n\n\n");
}
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... |