Submission #668390

# Submission time Handle Problem Language Result Execution time Memory
668390 2022-12-03T19:02:20 Z 600Mihnea Journey (NOI18_journey) C++17
69 / 100
2000 ms 6224 KB
#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, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++)
  {
    for (int cur = 0; cur <= m; cur++)
    {
      for (auto &it : g[i])
      {
        for (int stay = it.stay; cur + stay < m; stay++)
        {
          addup(dp[it.nxt][cur + stay], dp[i][cur]);
        }
      }
    }
  }

  for (int i = 0; i < m; i++)
  {
    cout << dp[n - 1][i] << " ";
  }
  cout << "\n";

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 48 ms 340 KB Output is correct
6 Correct 42 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 48 ms 340 KB Output is correct
6 Correct 42 ms 396 KB Output is correct
7 Correct 211 ms 5076 KB Output is correct
8 Execution timed out 2062 ms 6224 KB Time limit exceeded
9 Halted 0 ms 0 KB -