답안 #627746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627746 2022-08-12T21:29:13 Z tutis 메기 농장 (IOI22_fish) C++17
40 / 100
1000 ms 43672 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 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;
                }
            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));
            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;
                }
            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 62 ms 22028 KB Output is correct
2 Correct 77 ms 24928 KB Output is correct
3 Correct 29 ms 19800 KB Output is correct
4 Correct 25 ms 19796 KB Output is correct
5 Correct 198 ms 38904 KB Output is correct
6 Correct 253 ms 43672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1088 ms 22856 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19796 KB Output is correct
2 Correct 24 ms 19772 KB Output is correct
3 Correct 60 ms 20820 KB Output is correct
4 Correct 49 ms 21840 KB Output is correct
5 Correct 116 ms 25248 KB Output is correct
6 Correct 96 ms 25268 KB Output is correct
7 Correct 99 ms 25268 KB Output is correct
8 Correct 102 ms 25240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 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 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
16 Correct 8 ms 432 KB Output is correct
17 Correct 544 ms 3332 KB Output is correct
18 Correct 611 ms 4580 KB Output is correct
19 Correct 320 ms 4348 KB Output is correct
20 Correct 332 ms 4352 KB Output is correct
21 Correct 329 ms 4236 KB Output is correct
22 Execution timed out 1094 ms 7776 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
16 Correct 8 ms 432 KB Output is correct
17 Correct 544 ms 3332 KB Output is correct
18 Correct 611 ms 4580 KB Output is correct
19 Correct 320 ms 4348 KB Output is correct
20 Correct 332 ms 4352 KB Output is correct
21 Correct 329 ms 4236 KB Output is correct
22 Execution timed out 1094 ms 7776 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19796 KB Output is correct
2 Correct 24 ms 19772 KB Output is correct
3 Correct 60 ms 20820 KB Output is correct
4 Correct 49 ms 21840 KB Output is correct
5 Correct 116 ms 25248 KB Output is correct
6 Correct 96 ms 25268 KB Output is correct
7 Correct 99 ms 25268 KB Output is correct
8 Correct 102 ms 25240 KB Output is correct
9 Correct 124 ms 25280 KB Output is correct
10 Correct 78 ms 16764 KB Output is correct
11 Correct 176 ms 33152 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 19864 KB Output is correct
19 Correct 25 ms 19772 KB Output is correct
20 Correct 25 ms 19796 KB Output is correct
21 Correct 29 ms 19824 KB Output is correct
22 Correct 112 ms 25848 KB Output is correct
23 Correct 210 ms 33228 KB Output is correct
24 Correct 180 ms 33220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 22028 KB Output is correct
2 Correct 77 ms 24928 KB Output is correct
3 Correct 29 ms 19800 KB Output is correct
4 Correct 25 ms 19796 KB Output is correct
5 Correct 198 ms 38904 KB Output is correct
6 Correct 253 ms 43672 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Execution timed out 1088 ms 22856 KB Time limit exceeded
9 Halted 0 ms 0 KB -