답안 #656326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656326 2022-11-06T23:58:32 Z Lobo 메기 농장 (IOI22_fish) C++17
37 / 100
1000 ms 129392 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

const int maxn = 1e5+10;
const int maxqh = 12;
const int inf = 1e18+10;

int n, m;
vector<vector<int>> dp[maxn];
map<int,int> pf[maxn];
vector<pair<int,int>> fish[maxn]; // fishs from column i
vector<int> hr[maxn]; // important heights from column i, the ones that can be chosen

long long max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
    n = N;
    m = M;

    for(int i = 0; i < m; i++) {
        fish[X[i]+1].pb(mp(Y[i]+1,W[i]));
        hr[X[i]+1].pb(Y[i]);
    }

    for(int i = 0; i <= n; i++) {
        hr[i].pb(0);
        hr[i].pb(n);
        sort(all(hr[i]));
        sort(all(fish[i]));
        hr[i].erase(unique(all(hr[i])),hr[i].end());
        // Store only the relevant heights

        for(int j = 0; j < hr[i].size(); j++) {
            dp[i].pb({0,0});
        }
    }

    for(int i = 1; i <= n; i++) {
        for(auto j : hr[i-1]) pf[i][j] = 0;
        for(auto j : hr[i]) pf[i][j] = 0;
        for(auto j : hr[i+1]) pf[i][j] = 0;

        for(auto aux : fish[i]) {
            int y = aux.fr;
            int w = aux.sc;
            pf[i][y]+= w;
        }
        // Do a prefix sum on the weight of the fishs
        pf[i][0] = 0;
        for(auto it = next(pf[i].begin()); it != pf[i].end(); it++) {
            it->sc+= prev(it)->sc;
        }
    }

    // dp[i][h0][0/1] = until i, with h[i] = hr[i][h0] 
    // and it's greater/smaller tha the previous

    // dp[1][h0][0/1] = 0
    for(int i = 0; i < hr[1].size(); i++) {
        dp[1][i][0] = 0;
        dp[1][i][1] = 0;
    }

    for(int i = 2; i <= n; i++) {
        for(int h0 = 0; h0 < hr[i].size(); h0++) {
            // It's greater than the previous
            dp[i][h0][0] = 0;
            for(int h1 = 0; h1 < hr[i-1].size(); h1++) {
                if(hr[i-1][h1] > hr[i][h0]) continue;
                dp[i][h0][0] = max(dp[i][h0][0], dp[i-1][h1][0] + pf[i-1][hr[i][h0]]-pf[i-1][hr[i-1][h1]]);
            }

            if(i != 2) {
                for(int h2 = 0; h2 < hr[i-2].size(); h2++) {
                    dp[i][h0][0] = max(dp[i][h0][0], dp[i-2][h2][1] + pf[i-1][max(hr[i][h0],hr[i-2][h2])]);
                    dp[i][h0][0] = max(dp[i][h0][0], dp[i-2][h2][0] + pf[i-1][max(hr[i][h0],hr[i-2][h2])]);
                }
            }

            // It's smaller than the previous
            dp[i][h0][1] = 0;
            for(int h1 = 0; h1 < hr[i-1].size(); h1++) {
                if(hr[i-1][h1] < hr[i][h0]) continue;
                dp[i][h0][1] = max(dp[i][h0][1], dp[i-1][h1][0] + pf[i][hr[i-1][h1]] - pf[i][hr[i][h0]]);
                dp[i][h0][1] = max(dp[i][h0][1], dp[i-1][h1][1] + pf[i][hr[i-1][h1]] - pf[i][hr[i][h0]]);
            }
        }
    }

    // cout << dp[2][hr[4].size()-1][1] << endl;

    int ans = 0;
    for(int h0 = 0; h0 < hr[n].size(); h0++) {
        ans = max(ans, dp[n][h0][0]);
        ans = max(ans, dp[n][h0][1]);
    }
    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:38:26: 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]
   38 |         for(int j = 0; j < hr[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~
fish.cpp:64:22: 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]
   64 |     for(int i = 0; i < hr[1].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
fish.cpp:70:28: 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 |         for(int h0 = 0; h0 < hr[i].size(); h0++) {
      |                         ~~~^~~~~~~~~~~~~~
fish.cpp:73:32: 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 |             for(int h1 = 0; h1 < hr[i-1].size(); h1++) {
      |                             ~~~^~~~~~~~~~~~~~~~
fish.cpp:79:36: 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]
   79 |                 for(int h2 = 0; h2 < hr[i-2].size(); h2++) {
      |                                 ~~~^~~~~~~~~~~~~~~~
fish.cpp:87:32: 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 h1 = 0; h1 < hr[i-1].size(); h1++) {
      |                             ~~~^~~~~~~~~~~~~~~~
fish.cpp:98:24: 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]
   98 |     for(int h0 = 0; h0 < hr[n].size(); h0++) {
      |                     ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 56132 KB Output is correct
2 Correct 248 ms 62976 KB Output is correct
3 Correct 59 ms 40152 KB Output is correct
4 Correct 61 ms 40184 KB Output is correct
5 Execution timed out 1065 ms 129392 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11988 KB Output is correct
2 Execution timed out 1099 ms 70244 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 40140 KB Output is correct
2 Correct 59 ms 40104 KB Output is correct
3 Correct 98 ms 44452 KB Output is correct
4 Correct 89 ms 45016 KB Output is correct
5 Correct 166 ms 53528 KB Output is correct
6 Correct 142 ms 53528 KB Output is correct
7 Correct 146 ms 53412 KB Output is correct
8 Correct 143 ms 53524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 12040 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 6 ms 12040 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 9 ms 12500 KB Output is correct
11 Correct 7 ms 12252 KB Output is correct
12 Correct 8 ms 12404 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 7 ms 12244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 12040 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 6 ms 12040 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 9 ms 12500 KB Output is correct
11 Correct 7 ms 12252 KB Output is correct
12 Correct 8 ms 12404 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 7 ms 12244 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 20 ms 12500 KB Output is correct
17 Execution timed out 1078 ms 20812 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 12040 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 7 ms 11988 KB Output is correct
7 Correct 6 ms 12040 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 9 ms 12500 KB Output is correct
11 Correct 7 ms 12252 KB Output is correct
12 Correct 8 ms 12404 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 7 ms 12244 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 20 ms 12500 KB Output is correct
17 Execution timed out 1078 ms 20812 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 40140 KB Output is correct
2 Correct 59 ms 40104 KB Output is correct
3 Correct 98 ms 44452 KB Output is correct
4 Correct 89 ms 45016 KB Output is correct
5 Correct 166 ms 53528 KB Output is correct
6 Correct 142 ms 53528 KB Output is correct
7 Correct 146 ms 53412 KB Output is correct
8 Correct 143 ms 53524 KB Output is correct
9 Correct 186 ms 73804 KB Output is correct
10 Correct 106 ms 41760 KB Output is correct
11 Correct 238 ms 71600 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12000 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 6 ms 11988 KB Output is correct
17 Correct 6 ms 11932 KB Output is correct
18 Correct 60 ms 40200 KB Output is correct
19 Correct 61 ms 40200 KB Output is correct
20 Correct 66 ms 40192 KB Output is correct
21 Correct 61 ms 40148 KB Output is correct
22 Correct 216 ms 77328 KB Output is correct
23 Correct 290 ms 86708 KB Output is correct
24 Correct 289 ms 88824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 56132 KB Output is correct
2 Correct 248 ms 62976 KB Output is correct
3 Correct 59 ms 40152 KB Output is correct
4 Correct 61 ms 40184 KB Output is correct
5 Execution timed out 1065 ms 129392 KB Time limit exceeded
6 Halted 0 ms 0 KB -