Submission #673006

# Submission time Handle Problem Language Result Execution time Memory
673006 2022-12-19T11:17:56 Z pls33 Catfish Farm (IOI22_fish) C++17
14 / 100
1000 ms 2097152 KB
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
#pragma region dalykai
using p32 = pair<int, int>;
using p32u = pair<uint32_t, uint32_t>;
using p64 = pair<int64_t, int64_t>;
using p64u = pair<uint64_t, uint64_t>;
using vi16 = vector<int16_t>;
using vi16u = vector<uint16_t>;
using vi32 = vector<int>;
using vi32u = vector<uint32_t>;
using vi64 = vector<int64_t>;
using vi64u = vector<uint64_t>;
using vp32 = vector<p32>;
using vp32u = vector<p32u>;
using vp64 = vector<p64>;
using vp64u = vector<p64u>;
using vvi32 = vector<vi32>;
using vvi32u = vector<vi32u>;
using vvi64 = vector<vi64>;
using vvi64u = vector<vi64u>;
using vvp32 = vector<vp32>;
using vvp32u = vector<vp32u>;
using vvp64 = vector<vp64>;
using vvp64u = vector<vp64u>;
#pragma endregion

void update(int64_t val, p32 fish, vvi64 &vect)
{
    vect[fish.first][fish.second] = max(vect[fish.first][fish.second], val);
}

int64_t weight_sum(int i, int j, vvi64 &prefix, int row)
{
    if (i == -1)
    {
        return 0;
    }

    int64_t sum = prefix[row][j];
    if (i)
    {
        sum -= prefix[row][i - 1];
    }

    return sum;
}

int64_t new_weight(p32 lhs, p32 rhs, vvi64 &prefix){
    long left = rhs.first > 0
                        ? weight_sum(0, rhs.second, prefix, rhs.first - 1)
                        : 0;

    long right = (rhs.first + 1 < (int)prefix.size())
                        ? weight_sum(0, rhs.second, prefix, rhs.first + 1)
                        : 0;

    if (lhs.first == -1)
    {
        return left + right;
    }

    if (rhs.first - lhs.first > 2)
    {
        return left + right;
    }

    if (rhs.first - lhs.first == 2)
    {
        if (lhs.second >= rhs.second)
        {
            return right;
        }

        left -= weight_sum(0, lhs.second, prefix, rhs.first - 1);

        return left + right;
    }

    if (lhs.second > rhs.second)
    {
        left = -weight_sum(0, rhs.second, prefix, rhs.first);
        return left + right;
    }

    left -= weight_sum(0, lhs.second, prefix, rhs.first) +
            weight_sum(0, lhs.second, prefix, rhs.first - 1);
    return left + right;
}

long long max_weights(int N, int M,
                      std::vector<int> X,
                      std::vector<int> Y,
                      std::vector<int> W)
{
    vp32 fish;
    vvi64 prefix(N, vi64(N));
    for (int i = 0; i < M; i++)
    {
        prefix[X[i]][Y[i]] = W[i];

        if (X[i])
        {
            fish.push_back({X[i] - 1, Y[i]});
        }
        if (X[i] < N - 1)
        {
            fish.push_back({X[i] + 1, Y[i]});
        }
    }

    for (auto &row : prefix)
    {
        for (int i = 1; i < (int)row.size(); i++)
        {
            row[i] += row[i - 1];
        }
    }

    sort(fish.begin(), fish.end());
    auto it = unique(fish.begin(), fish.end());
    fish.erase(it, fish.end());

    vvi64 decrease(N, vi64(N));
    vvi64 increase(N, vi64(N));

    vp32 check;
    for (auto &f : fish)
    {
        int64_t initial = new_weight(p32(-1, -1), f, prefix);
        update(initial, f, increase);
        update(initial, f, decrease);
        check.push_back(f);

        for(int cur = 0; cur < (int)check.size() - 1; cur++){
            auto &[i, j] = check[cur];

            if(i == f.first || check[cur] == f){
                continue;
            }

            int64_t prev = new_weight(p32(i, j), f, prefix);

            if(i == f.first - 1){
                if(j < f.second){
                    update(prev + increase[i][j], f, increase);
                }
                else {
                    update(prev + decrease[i][j], f, decrease);
                }
            }
            else {
                prev += max(increase[i][j], decrease[i][j]);
                update(prev, f, increase);
                update(prev, f, decrease);
            }
        }
    }

    int64_t res = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            res = max({res, increase[i][j], decrease[i][j]});
        }
    }
    return res;
}

Compilation message

fish.cpp:4: warning: ignoring '#pragma region dalykai' [-Wunknown-pragmas]
    4 | #pragma region dalykai
      | 
fish.cpp:27: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
   27 | #pragma endregion
      |
# Verdict Execution time Memory Grader output
1 Execution timed out 1164 ms 2043848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 814 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 766 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 25 ms 2576 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 19 ms 2516 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 2388 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 25 ms 2576 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 19 ms 2516 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 2388 KB Output is correct
15 Correct 5 ms 2476 KB Output is correct
16 Correct 31 ms 564 KB Output is correct
17 Execution timed out 1090 ms 4612 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 25 ms 2576 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 19 ms 2516 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 2388 KB Output is correct
15 Correct 5 ms 2476 KB Output is correct
16 Correct 31 ms 564 KB Output is correct
17 Execution timed out 1090 ms 4612 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 766 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1164 ms 2043848 KB Time limit exceeded
2 Halted 0 ms 0 KB -