Submission #705159

# Submission time Handle Problem Language Result Execution time Memory
705159 2023-03-03T13:10:36 Z danikoynov Catfish Farm (IOI22_fish) C++17
44 / 100
112 ms 14056 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10, smalln = 310;

vector < pair < int, int > > col[maxn];
ll dp[smalln][smalln][2];
ll val[smalln][smalln], pref[smalln][smalln];

ll get_sum(int col, int left, int right)
{
    ll sum = pref[col][right];
    if (left > 0)
        sum = sum - pref[col][left - 1];
    return sum;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W)
{
    bool all_even = true, small_x = true;
    for (int i = 0; i < M; i ++)
    {
        if (X[i] % 2 != 0)
            all_even = false;
        if (X[i] > 1)
            small_x = false;
    }

    for (int i = 0; i < M; i ++)
    {
        col[X[i]].push_back({Y[i], W[i]});
    }

    for (int i = 0; i < N; i ++)
        sort(col[i].begin(), col[i].end());

    if (all_even)
    {
        ll sum = 0;
        for (int i = 0; i < M; i ++)
            sum = sum + W[i];
        return sum;

    }
    else if (small_x)
    {

        ll zero = 0, one = 0;
        for (int i = 0; i < M; i ++)
        {
            if (X[i] == 0)
                zero += W[i];
            else
                one += W[i];
        }
        if (N == 2)
            return max(zero, one);

        int to = 0;
        ll cur = 0, ans = 0;
        for (int i = 0; i < col[0].size(); i ++)
        {
            if (cur + one > ans)
                ans = cur + one;
            cur += col[0][i].second;
            while(to < col[1].size() && col[1][to].first <= col[0][i].first)
            {
                one -= col[1][to].second;
                to ++;
            }
        }
        if (cur + one > ans)
            ans = cur + one;
        return ans;

    }

    for (int i = 0; i < M; i ++)
    val[X[i]][Y[i]] = W[i];

    /**for (int i = 0; i < N; i ++, cout << endl)
        for (int j = 0; j < N; j ++)
        cout << val[i][j] << " ";*/
    for (int j = 0; j <= N; j ++)
        dp[1][j][0] = dp[1][j][1] = 0;

    for (int i = 0; i < N; i ++)
    {
        pref[i][0] = val[i][0];
        for (int j = 1; j <= N; j ++)
        {
            pref[i][j] = pref[i][j - 1] + val[i][j];
        }
    }
    for (int i = 1; i < N; i ++)
    {

        dp[i][0][1] = dp[i - 1][0][1];
        for (int j = 1; j <= N; j ++)
        {
            dp[i][j][1] = max(dp[i][j - 1][1] + val[i - 1][j - 1], dp[i - 1][j][1]);
        }
        for (int j = 0; j <= N; j ++)
        {
            /**for (int len = 0; len < j; len ++)
            {
                //cout << i << " " << j << " " << len << " " << get_sum(i - 1, len, j - 1) << endl;
                //cout << pref[i - 1][j - 1] << endl;
                dp[i][j][1] = max(dp[i][j][1], dp[i - 1][len][1] + get_sum(i - 1, len, j - 1));
            }*/

            dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][1]);
            dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][0]);
            dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][0]);
            dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][1]);

            for (int len = j + 1; len <= N; len ++)
            {
                dp[i][j][0] = max(dp[i][j][0], max(dp[i - 1][len][0], dp[i - 1][len][1]) + get_sum(i, j, len - 1));
            }

            if (i > 1 && j > 0)
            {
                for (int len = 0; len <= N; len ++)
                {
                    dp[i][j][1] = max(dp[i][j][1], max(dp[i - 2][len][0], dp[i - 2][len][1]) + get_sum(i - 1, 0, max(len, j) - 1));
                }
            }
        }
    }

    /**cout << "-----------" << endl;
    for (int i = 0; i < N; i ++, cout << endl)
        for (int j = 0; j <= N; j ++)
        cout << dp[i][j][0] << " ";
    cout << "-----------" << endl;
    for (int i = 0; i < N; i ++, cout << endl)
        for (int j = 0; j <= N; j ++)
        cout << dp[i][j][1] << " ";*/
    ll ans = 0;
    for (int j = 0; j <= N; j ++)
    for (int t = 0; t < 2; t ++)
    ans = max(ans, dp[N - 1][j][t]);


    return ans;

}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i = 0; i < col[0].size(); i ++)
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             while(to < col[1].size() && col[1][to].first <= col[0][i].first)
      |                   ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5708 KB Output is correct
2 Correct 35 ms 6132 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 104 ms 12288 KB Output is correct
6 Correct 112 ms 14056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 65 ms 8060 KB Output is correct
3 Correct 73 ms 9088 KB Output is correct
4 Correct 31 ms 5700 KB Output is correct
5 Correct 44 ms 6116 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 31 ms 5656 KB Output is correct
13 Correct 40 ms 6132 KB Output is correct
14 Correct 30 ms 5428 KB Output is correct
15 Correct 36 ms 5704 KB Output is correct
16 Correct 30 ms 5580 KB Output is correct
17 Correct 33 ms 5748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Runtime error 4 ms 5172 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 13 ms 4052 KB Output is correct
10 Correct 92 ms 5584 KB Output is correct
11 Correct 12 ms 4052 KB Output is correct
12 Correct 82 ms 5648 KB Output is correct
13 Correct 3 ms 3284 KB Output is correct
14 Correct 77 ms 5568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 13 ms 4052 KB Output is correct
10 Correct 92 ms 5584 KB Output is correct
11 Correct 12 ms 4052 KB Output is correct
12 Correct 82 ms 5648 KB Output is correct
13 Correct 3 ms 3284 KB Output is correct
14 Correct 77 ms 5568 KB Output is correct
15 Correct 75 ms 5480 KB Output is correct
16 Correct 4 ms 3284 KB Output is correct
17 Correct 89 ms 6860 KB Output is correct
18 Correct 86 ms 7156 KB Output is correct
19 Correct 91 ms 7280 KB Output is correct
20 Correct 96 ms 7284 KB Output is correct
21 Correct 87 ms 7224 KB Output is correct
22 Correct 102 ms 9028 KB Output is correct
23 Correct 77 ms 5788 KB Output is correct
24 Correct 87 ms 6588 KB Output is correct
25 Correct 76 ms 5580 KB Output is correct
26 Correct 79 ms 5788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 13 ms 4052 KB Output is correct
10 Correct 92 ms 5584 KB Output is correct
11 Correct 12 ms 4052 KB Output is correct
12 Correct 82 ms 5648 KB Output is correct
13 Correct 3 ms 3284 KB Output is correct
14 Correct 77 ms 5568 KB Output is correct
15 Correct 75 ms 5480 KB Output is correct
16 Correct 4 ms 3284 KB Output is correct
17 Correct 89 ms 6860 KB Output is correct
18 Correct 86 ms 7156 KB Output is correct
19 Correct 91 ms 7280 KB Output is correct
20 Correct 96 ms 7284 KB Output is correct
21 Correct 87 ms 7224 KB Output is correct
22 Correct 102 ms 9028 KB Output is correct
23 Correct 77 ms 5788 KB Output is correct
24 Correct 87 ms 6588 KB Output is correct
25 Correct 76 ms 5580 KB Output is correct
26 Correct 79 ms 5788 KB Output is correct
27 Runtime error 4 ms 5460 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Runtime error 4 ms 5172 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5708 KB Output is correct
2 Correct 35 ms 6132 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 104 ms 12288 KB Output is correct
6 Correct 112 ms 14056 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 65 ms 8060 KB Output is correct
9 Correct 73 ms 9088 KB Output is correct
10 Correct 31 ms 5700 KB Output is correct
11 Correct 44 ms 6116 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 31 ms 5656 KB Output is correct
19 Correct 40 ms 6132 KB Output is correct
20 Correct 30 ms 5428 KB Output is correct
21 Correct 36 ms 5704 KB Output is correct
22 Correct 30 ms 5580 KB Output is correct
23 Correct 33 ms 5748 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Runtime error 4 ms 5172 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -