답안 #627747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627747 2022-08-12T21:32:08 Z tutis 메기 농장 (IOI22_fish) C++17
40 / 100
1000 ms 41036 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long max_weights(int N, int MM, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    vector<pair<int, ll>>P[N];
    vector<int>Q_[N + 4];
    vector<int>*Q = Q_ + 2;
    for (int i = 0; i < MM; i++)
    {
        P[X[i]].push_back({Y[i], W[i]});
        Q[X[i]].push_back(Y[i]);
    }
    for (int i = -1; i <= N; i++)
    {
        Q[i].push_back(N);
    }
    for (int i = 0; i < N; i++)
    {
        sort(P[i].begin(), P[i].end());
        for (int j = 1; j < (int)P[i].size(); j++)
            P[i][j].second += P[i][j - 1].second;
        sort(Q[i].begin(), Q[i].end());
    }
    ll dp_[N + 3];
    ll* dp = dp_ + 2;
    for (int i = -2; i <= N; i++)
        dp[i] = 0;
    vector<ll> u[N];
    vector<ll> d[N];
    auto get = [&](int x, int y)->ll
    {
        if (x < 0 || x >= N)
            return 0;
        auto it = lower_bound(P[x].begin(), P[x].end(), make_pair(y + 1, -1ll));
        if (it == P[x].begin())
            return 0;
        it--;
        return it->second;
    };
    ll vv = 0;
    for (int x = 0; x < N; x++)
    {
        dp[x] = dp[x - 1];
        dp[x] = max(dp[x], vv);
        vv = 0;
        for (int y : Q[x - 1])
            u[x].push_back(0);
        for (int y : Q[x + 1])
            d[x].push_back(0);
        for (int i = 0; i < (int)Q[x - 1].size(); i++)
        {
            ll&v = u[x][i];
            int y = Q[x - 1][i];
            v = max(v, dp[x - 1]);
            v = max(v, dp[x - 2] + get(x - 1, y));
        }
        if (x != 0)
            for (int i = 0; i < (int)Q[x - 1].size(); i++)
            {
                ll&v = u[x][i];
                int y = Q[x - 1][i];
                for (int j = 0; j < (int)Q[x - 2].size(); j++)
                {
                    if (Q[x - 2][j] < y)
                        v = max(v, u[x - 1][j] + get(x - 1, y) - get(x - 1, Q[x - 2][j]));
                    else
                        break;
                }
            }
        for (int i = 0; i < (int)Q[x - 1].size(); i++)
        {
            ll&v = u[x][i];
            int y = Q[x - 1][i];
            dp[x] = max(dp[x], v);
            vv = max(vv, v + get(x + 1, y));
        }
        for (int i = 0; i < (int)Q[x + 1].size(); i++)
        {
            ll&v = d[x][i];
            int y = Q[x + 1][i];
            if (y == N)
                v = max(v, u[x].back());
            v = max(v, dp[x - 1]);
            v = max(v, dp[x - 2] + get(x - 1, y));
        }
        for (int i = 0; i < (int)Q[x + 1].size(); i++)
        {
            ll&v = d[x][i];
            int y = Q[x + 1][i];
            if (x != 0)
                for (int j = (int)Q[x].size() - 1; j >= 0; j--)
                {
                    if (Q[x][j] > y)
                        v = max(v, d[x - 1][j] + get(x, Q[x][j]) - get(x, y));
                    else
                        break;
                }
        }
        for (int i = 0; i < (int)Q[x + 1].size(); i++)
        {
            ll&v = d[x][i];
            int y = Q[x + 1][i];
            dp[x] = max(dp[x], v);
            vv = max(vv, v + get(x + 1, y));
        }
    }
    return dp[N - 1];
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:49:18: warning: unused variable 'y' [-Wunused-variable]
   49 |         for (int y : Q[x - 1])
      |                  ^
fish.cpp:51:18: warning: unused variable 'y' [-Wunused-variable]
   51 |         for (int y : Q[x + 1])
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 21972 KB Output is correct
2 Correct 73 ms 24892 KB Output is correct
3 Correct 28 ms 19844 KB Output is correct
4 Correct 31 ms 19844 KB Output is correct
5 Correct 204 ms 38900 KB Output is correct
6 Correct 243 ms 41036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1091 ms 22912 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19868 KB Output is correct
2 Correct 27 ms 19868 KB Output is correct
3 Correct 59 ms 20820 KB Output is correct
4 Correct 49 ms 21728 KB Output is correct
5 Correct 124 ms 25248 KB Output is correct
6 Correct 110 ms 25292 KB Output is correct
7 Correct 99 ms 25348 KB Output is correct
8 Correct 115 ms 25276 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
6 Correct 1 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 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
6 Correct 1 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 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 517 ms 3364 KB Output is correct
18 Correct 593 ms 4572 KB Output is correct
19 Correct 333 ms 4172 KB Output is correct
20 Correct 323 ms 4252 KB Output is correct
21 Correct 365 ms 4244 KB Output is correct
22 Execution timed out 1086 ms 7884 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
6 Correct 1 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 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 517 ms 3364 KB Output is correct
18 Correct 593 ms 4572 KB Output is correct
19 Correct 333 ms 4172 KB Output is correct
20 Correct 323 ms 4252 KB Output is correct
21 Correct 365 ms 4244 KB Output is correct
22 Execution timed out 1086 ms 7884 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19868 KB Output is correct
2 Correct 27 ms 19868 KB Output is correct
3 Correct 59 ms 20820 KB Output is correct
4 Correct 49 ms 21728 KB Output is correct
5 Correct 124 ms 25248 KB Output is correct
6 Correct 110 ms 25292 KB Output is correct
7 Correct 99 ms 25348 KB Output is correct
8 Correct 115 ms 25276 KB Output is correct
9 Correct 117 ms 25300 KB Output is correct
10 Correct 77 ms 16672 KB Output is correct
11 Correct 198 ms 33104 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 25 ms 19824 KB Output is correct
19 Correct 25 ms 19860 KB Output is correct
20 Correct 25 ms 19796 KB Output is correct
21 Correct 24 ms 19744 KB Output is correct
22 Correct 104 ms 25824 KB Output is correct
23 Correct 175 ms 33180 KB Output is correct
24 Correct 176 ms 33108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 21972 KB Output is correct
2 Correct 73 ms 24892 KB Output is correct
3 Correct 28 ms 19844 KB Output is correct
4 Correct 31 ms 19844 KB Output is correct
5 Correct 204 ms 38900 KB Output is correct
6 Correct 243 ms 41036 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Execution timed out 1091 ms 22912 KB Time limit exceeded
9 Halted 0 ms 0 KB -