Submission #1057423

# Submission time Handle Problem Language Result Execution time Memory
1057423 2024-08-13T19:08:39 Z aykhn Catfish Farm (IOI22_fish) C++17
20 / 100
303 ms 167652 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MXN = 2e5 + 5;


long long mx[MXN];
vector<long long> lft[MXN], rig[MXN], in[MXN];
vector<long long> pre[2][MXN], suf[2][MXN];
vector<long long> dp[2][MXN];
vector<long long> ind[MXN];
vector<array<long long, 2>> val[MXN];

/*
0 = len[i] < len[i + 1];
1 = len[i] > len[i + 1];
*/
int A[9] = {0, 0, 0, -1, -1, -1, 1, 1, 1};
int B[9] = {0, -1, 1, 0, -1, 1, 0, -1, 1};
long long max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) 
{
    for (int i = 0; i < M; i++)
    {
        X[i]++, Y[i]++;
        for (int j = 0; j < 9; j++)
        {
            int x = X[i] + A[j], y = Y[i] + B[j];
            if (min(x, y) >= 1 && max(x, y) <= N)
            {
                ind[x].push_back(y);
            }
        }
        val[X[i]].push_back({Y[i], W[i]});
    }
    for (int i = 1; i <= N; i++)
    {
        sort(ind[i].begin(), ind[i].end());
        ind[i].resize(unique(ind[i].begin(), ind[i].end()) - ind[i].begin());
        sort(ind[i].begin(), ind[i].end()), sort(val[i].begin(), val[i].end());
    }
    for (int i = 1; i <= N; i++) 
    {
        int k1 = 0, k2 = 0, k3 = 0;
        for (int j = 0; j < ind[i].size(); j++)
        {
            lft[i].push_back((lft[i].empty() ? 0LL : lft[i].back()));
            rig[i].push_back((rig[i].empty() ? 0LL : rig[i].back()));
            in[i].push_back((in[i].empty() ? 0LL : in[i].back()));
            while (k1 < val[i - 1].size() && val[i - 1][k1][0] <= ind[i][j]) lft[i][j] += val[i - 1][k1][1], k1++;
            while (k2 < val[i + 1].size() && val[i + 1][k2][0] <= ind[i][j]) rig[i][j] += val[i + 1][k2][1], k2++;
            while (k3 < val[i].size() && val[i][k3][0] <= ind[i][j]) in[i][j] += val[i][k3][1], k3++;
        }
        
    }
    for (int i = 1; i <= N; i++)
    {
        int k1 = 0, k2 = 0, k3 = 0, k4 = 0;
        for (int j = 0; j < ind[i].size(); j++)
        {
            dp[0][i].push_back(lft[i][j] + rig[i][j]);
            dp[1][i].push_back(lft[i][j] + rig[i][j]);
            if (i <= 1) continue;
            while (k1 < ind[i - 1].size() && ind[i - 1][k1] <= ind[i][j]) k1++;
            while (k2 < ind[i - 1].size() && ind[i - 1][k2] < ind[i][j]) k2++;
            if (k1 - 1 >= 0) dp[0][i][j] = max(dp[0][i][j], pre[0][i - 1][k1 - 1] + (lft[i][j] + rig[i][j]));
            if (k2 < ind[i - 1].size()) dp[1][i][j] = max(dp[1][i][j], suf[0][i - 1][k2] + (rig[i][j] - in[i][j]));
            if (i <= 2) continue;
            while (k3 < ind[i - 2].size() && ind[i - 2][k3] <= ind[i][j]) k3++;
            while (k4 < ind[i - 2].size() && ind[i - 2][k4] < ind[i][j]) k4++;
            long long A = (k3 - 1 >= 0 ? pre[1][i - 2][k3 - 1] : 0) + lft[i][j] + rig[i][j];
            long long B = (k4 < ind[i - 2].size() ? suf[1][i - 2][k4] : 0) + rig[i][j];
            dp[0][i][j] = max({dp[0][i][j], A, B});
            dp[1][i][j] = max({dp[1][i][j], A, B});
            if (i <= 3) continue;
            dp[0][i][j] = max(dp[0][i][j], mx[i - 3] + lft[i][j] + rig[i][j]);
            dp[1][i][j] = max(dp[1][i][j], mx[i - 3] + lft[i][j] + rig[i][j]);
        }
        for (int j = 0; j < ind[i].size(); j++)
        {
            dp[1][i][j] = max(dp[1][i][j], dp[0][i][j]);
            mx[i] = max({mx[i], dp[0][i][j], dp[1][i][j]});
        }
        for (int j = 0; j < ind[i].size(); j++) 
        {
            pre[0][i].push_back(max((pre[0][i].empty() ? 0LL : pre[0][i].back()), dp[0][i][j] - rig[i][j] - in[i][j]));
            pre[1][i].push_back(max((pre[1][i].empty() ? 0LL : pre[1][i].back()), max(dp[0][i][j], dp[1][i][j]) - rig[i][j]));
        }
        suf[0][i].assign(ind[i].size(), 0);
        suf[1][i].assign(ind[i].size(), 0);
        for (int j = (int)ind[i].size() - 1; j >= 0; j--)
        {
            if (j + 1 < ind[i].size()) suf[0][i][j] = suf[0][i][j + 1], suf[1][i][j] = suf[1][i][j + 1];
            suf[0][i][j] = max(suf[0][i][j], dp[1][i][j]);
            suf[1][i][j] = max(suf[1][i][j], max(dp[0][i][j], dp[1][i][j]));
        }
    }
    long long ans = 0;
    for (int i = 1; i <= N; i++) 
    {
        for (long long &j : dp[0][i]) ans = max(ans, j);
        for (long long &j : dp[1][i]) ans = max(ans, j);
    }
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:48:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int j = 0; j < ind[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:53:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             while (k1 < val[i - 1].size() && val[i - 1][k1][0] <= ind[i][j]) lft[i][j] += val[i - 1][k1][1], k1++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:54:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             while (k2 < val[i + 1].size() && val[i + 1][k2][0] <= ind[i][j]) rig[i][j] += val[i + 1][k2][1], k2++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:55:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             while (k3 < val[i].size() && val[i][k3][0] <= ind[i][j]) in[i][j] += val[i][k3][1], k3++;
      |                    ~~~^~~~~~~~~~~~~~~
fish.cpp:62:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int j = 0; j < ind[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:67:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             while (k1 < ind[i - 1].size() && ind[i - 1][k1] <= ind[i][j]) k1++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:68:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             while (k2 < ind[i - 1].size() && ind[i - 1][k2] < ind[i][j]) k2++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:70:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             if (k2 < ind[i - 1].size()) dp[1][i][j] = max(dp[1][i][j], suf[0][i - 1][k2] + (rig[i][j] - in[i][j]));
      |                 ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:72:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             while (k3 < ind[i - 2].size() && ind[i - 2][k3] <= ind[i][j]) k3++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:73:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             while (k4 < ind[i - 2].size() && ind[i - 2][k4] < ind[i][j]) k4++;
      |                    ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:75:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             long long B = (k4 < ind[i - 2].size() ? suf[1][i - 2][k4] : 0) + rig[i][j];
      |                            ~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:82:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (int j = 0; j < ind[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:87:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for (int j = 0; j < ind[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:96:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |             if (j + 1 < ind[i].size()) suf[0][i][j] = suf[0][i][j + 1], suf[1][i][j] = suf[1][i][j + 1];
      |                 ~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 72 ms 73524 KB Output is correct
2 Correct 82 ms 79476 KB Output is correct
3 Correct 9 ms 51888 KB Output is correct
4 Correct 8 ms 52216 KB Output is correct
5 Incorrect 303 ms 167652 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '44945481875572'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 52056 KB Output is correct
2 Correct 125 ms 90268 KB Output is correct
3 Correct 162 ms 98080 KB Output is correct
4 Correct 66 ms 73528 KB Output is correct
5 Correct 76 ms 79536 KB Output is correct
6 Correct 8 ms 51884 KB Output is correct
7 Correct 7 ms 52100 KB Output is correct
8 Correct 7 ms 52056 KB Output is correct
9 Correct 8 ms 52060 KB Output is correct
10 Correct 9 ms 52060 KB Output is correct
11 Correct 9 ms 51900 KB Output is correct
12 Correct 83 ms 82148 KB Output is correct
13 Correct 95 ms 90232 KB Output is correct
14 Correct 75 ms 77980 KB Output is correct
15 Correct 76 ms 74372 KB Output is correct
16 Correct 75 ms 78376 KB Output is correct
17 Correct 79 ms 83136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 52104 KB Output is correct
2 Correct 10 ms 52060 KB Output is correct
3 Incorrect 80 ms 76604 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '369591758422'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 52060 KB Output is correct
2 Correct 8 ms 52084 KB Output is correct
3 Correct 7 ms 51872 KB Output is correct
4 Correct 8 ms 51896 KB Output is correct
5 Correct 9 ms 51876 KB Output is correct
6 Correct 7 ms 51908 KB Output is correct
7 Correct 8 ms 51884 KB Output is correct
8 Correct 8 ms 52060 KB Output is correct
9 Correct 8 ms 52056 KB Output is correct
10 Correct 9 ms 52660 KB Output is correct
11 Correct 8 ms 52316 KB Output is correct
12 Correct 8 ms 52620 KB Output is correct
13 Correct 8 ms 52060 KB Output is correct
14 Correct 7 ms 52320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 52060 KB Output is correct
2 Correct 8 ms 52084 KB Output is correct
3 Correct 7 ms 51872 KB Output is correct
4 Correct 8 ms 51896 KB Output is correct
5 Correct 9 ms 51876 KB Output is correct
6 Correct 7 ms 51908 KB Output is correct
7 Correct 8 ms 51884 KB Output is correct
8 Correct 8 ms 52060 KB Output is correct
9 Correct 8 ms 52056 KB Output is correct
10 Correct 9 ms 52660 KB Output is correct
11 Correct 8 ms 52316 KB Output is correct
12 Correct 8 ms 52620 KB Output is correct
13 Correct 8 ms 52060 KB Output is correct
14 Correct 7 ms 52320 KB Output is correct
15 Correct 7 ms 52324 KB Output is correct
16 Incorrect 8 ms 52828 KB 1st lines differ - on the 1st token, expected: '741526820812', found: '314050587306'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 52060 KB Output is correct
2 Correct 8 ms 52084 KB Output is correct
3 Correct 7 ms 51872 KB Output is correct
4 Correct 8 ms 51896 KB Output is correct
5 Correct 9 ms 51876 KB Output is correct
6 Correct 7 ms 51908 KB Output is correct
7 Correct 8 ms 51884 KB Output is correct
8 Correct 8 ms 52060 KB Output is correct
9 Correct 8 ms 52056 KB Output is correct
10 Correct 9 ms 52660 KB Output is correct
11 Correct 8 ms 52316 KB Output is correct
12 Correct 8 ms 52620 KB Output is correct
13 Correct 8 ms 52060 KB Output is correct
14 Correct 7 ms 52320 KB Output is correct
15 Correct 7 ms 52324 KB Output is correct
16 Incorrect 8 ms 52828 KB 1st lines differ - on the 1st token, expected: '741526820812', found: '314050587306'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 52104 KB Output is correct
2 Correct 10 ms 52060 KB Output is correct
3 Incorrect 80 ms 76604 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '369591758422'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 73524 KB Output is correct
2 Correct 82 ms 79476 KB Output is correct
3 Correct 9 ms 51888 KB Output is correct
4 Correct 8 ms 52216 KB Output is correct
5 Incorrect 303 ms 167652 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '44945481875572'
6 Halted 0 ms 0 KB -