Submission #927295

# Submission time Handle Problem Language Result Execution time Memory
927295 2024-02-14T16:10:40 Z boris_mihov Two Dishes (JOI19_dishes) C++17
10 / 100
70 ms 36296 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 2000 + 10;
const llong INF = 1e18;

int n, m;
struct Dish
{
    int time;
    llong limit;
    int reward;
    int idx;
    bool type;
};

Dish a[MAXN];
Dish b[MAXN];
llong prefixA[MAXN];
llong prefixB[MAXN];
llong dp[MAXN][MAXN];
bool bl[MAXN][MAXN];

llong f(int aPos, int bPos)
{
    if (aPos == n + 1 && bPos == m + 1)
    {
        return 0;
    }

    if (bl[aPos][bPos])
    {
        return dp[aPos][bPos];
    }

    bl[aPos][bPos] = true;
    dp[aPos][bPos] = -INF;
    llong sum = prefixA[aPos - 1] + prefixB[bPos - 1];

    if (aPos <= n)
    {
        dp[aPos][bPos] = std::max(dp[aPos][bPos], f(aPos + 1, bPos) + (sum + a[aPos].time <= a[aPos].limit ? a[aPos].reward : 0));
    }

    if (bPos <= m)
    {
        dp[aPos][bPos] = std::max(dp[aPos][bPos], f(aPos, bPos + 1) + (sum + b[bPos].time <= b[bPos].limit ? b[bPos].reward : 0));
    }

    return dp[aPos][bPos];
}

void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        prefixA[i] = prefixA[i - 1] + a[i].time;
    }

    for (int i = 1 ; i <= m ; ++i)
    {
        prefixB[i] = prefixB[i - 1] + b[i].time;
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = 1 ; j < m ; ++j)
        {
            assert(f(i, j) >= f(i, j + 1));
            // std::cout << f(i, j) << ' ';
        }

        // std::cout << '\n';
    }

    std::cout << f(1, 1) << '\n';
}

void input()
{
    std::cin >> n >> m;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i].time >> a[i].limit >> a[i].reward;
        a[i].idx = i;
        a[i].type = false;
    }

    for (int i = 1 ; i <= m ; ++i)
    {
        std::cin >> b[i].time >> b[i].limit >> b[i].reward;
        b[i].idx = i;
        a[i].type = true;
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2528 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2528 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2392 KB Output is correct
17 Correct 70 ms 36280 KB Output is correct
18 Correct 67 ms 36184 KB Output is correct
19 Correct 68 ms 36184 KB Output is correct
20 Correct 62 ms 36184 KB Output is correct
21 Correct 70 ms 35676 KB Output is correct
22 Correct 67 ms 36296 KB Output is correct
23 Correct 68 ms 36188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2528 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2392 KB Output is correct
17 Correct 70 ms 36280 KB Output is correct
18 Correct 67 ms 36184 KB Output is correct
19 Correct 68 ms 36184 KB Output is correct
20 Correct 62 ms 36184 KB Output is correct
21 Correct 70 ms 35676 KB Output is correct
22 Correct 67 ms 36296 KB Output is correct
23 Correct 68 ms 36188 KB Output is correct
24 Runtime error 3 ms 600 KB Execution killed with signal 11
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2528 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2392 KB Output is correct
17 Correct 70 ms 36280 KB Output is correct
18 Correct 67 ms 36184 KB Output is correct
19 Correct 68 ms 36184 KB Output is correct
20 Correct 62 ms 36184 KB Output is correct
21 Correct 70 ms 35676 KB Output is correct
22 Correct 67 ms 36296 KB Output is correct
23 Correct 68 ms 36188 KB Output is correct
24 Runtime error 3 ms 600 KB Execution killed with signal 11
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2528 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2392 KB Output is correct
17 Correct 70 ms 36280 KB Output is correct
18 Correct 67 ms 36184 KB Output is correct
19 Correct 68 ms 36184 KB Output is correct
20 Correct 62 ms 36184 KB Output is correct
21 Correct 70 ms 35676 KB Output is correct
22 Correct 67 ms 36296 KB Output is correct
23 Correct 68 ms 36188 KB Output is correct
24 Runtime error 3 ms 600 KB Execution killed with signal 11
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -