답안 #627013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627013 2022-08-12T04:40:49 Z jhhope1 메기 농장 (IOI22_fish) C++17
100 / 100
157 ms 26440 KB
#include <bits/stdc++.h>
#include "fish.h"

#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> tri;
const int MAXN = 100010;
const ll INF = 1e18;
vector<pii> HW[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    vector<tri> P;
    for(int i=0 ; i<M ; i++){
        P.emplace_back(pii(X[i], Y[i]), W[i]);
    }
    sort(P.begin(), P.end());
    for(int i=0 ; i<M ; i++){
        HW[P[i].first.first].emplace_back(P[i].first.second, P[i].second);
    }
    
    vector<ll> U(HW[0].size(), 0), D(HW[0].size(), 0);
    ll T = 0, S = 0;
    for(int j=0 ; j<HW[0].size() ; j++){
        S += HW[0][j].second;
        D[j] = S;
    }

    for(int i=1 ; i<N ; i++){
        vector<ll> new_U(HW[i].size(), 0), new_D(HW[i].size(), 0);
        ll S = 0, ma = -INF;
        for(int j=HW[i].size()-1 ; j>=0 ; j--){
            S += HW[i][j].second;
            new_U[j] = T + S;
        }
        S = 0;
        for(int j=HW[i].size()-1 ; j>=0 ; j--){
            auto [x, w] = HW[i][j];
            int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x+1, 0)) - HW[i-1].begin();
            if(idx < U.size()){
                ma = max(ma, U[idx] - S);
                new_U[j] = max(new_U[j], ma + (S + w));
            }
            S += w;
        }
        S = 0, ma = -INF;
        for(int j=0 ; j<HW[i].size() ; j++){
            S += HW[i][j].second;
            if(U.size())
                new_D[j] = U[0] + S;
            else
                new_D[j] = S;
        }
        S = 0;
        for(int j=0 ; j<HW[i].size() ; j++){
            auto [x, w] = HW[i][j];
            int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x, 0)) - HW[i-1].begin() - 1;
            if(idx >= 0 && idx < U.size()){
                ma = max(ma, D[idx] - S);
                new_D[j] = max(new_D[j], ma + (S + w));
            }
            S += w;
        }

        if(U.size()){
            T = max(T, U[0]);
            T = max(T, D[D.size()-1]);
        }
        U = new_U;
        D = new_D;
    }
    if(U.size()){
        T = max(T, U[0]);
    }
    return T;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int j=0 ; j<HW[0].size() ; j++){
      |                   ~^~~~~~~~~~~~~
fish.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             if(idx < U.size()){
      |                ~~~~^~~~~~~~~~
fish.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int j=0 ; j<HW[i].size() ; j++){
      |                       ~^~~~~~~~~~~~~
fish.cpp:55:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j=0 ; j<HW[i].size() ; j++){
      |                       ~^~~~~~~~~~~~~
fish.cpp:58:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             if(idx >= 0 && idx < U.size()){
      |                            ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10556 KB Output is correct
2 Correct 45 ms 11724 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 143 ms 26440 KB Output is correct
6 Correct 150 ms 24616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 78 ms 15848 KB Output is correct
3 Correct 101 ms 19196 KB Output is correct
4 Correct 37 ms 10040 KB Output is correct
5 Correct 44 ms 11316 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 4 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 37 ms 10612 KB Output is correct
13 Correct 46 ms 12480 KB Output is correct
14 Correct 41 ms 9472 KB Output is correct
15 Correct 47 ms 11060 KB Output is correct
16 Correct 44 ms 9432 KB Output is correct
17 Correct 44 ms 10408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 30 ms 7108 KB Output is correct
4 Correct 24 ms 5640 KB Output is correct
5 Correct 48 ms 10552 KB Output is correct
6 Correct 44 ms 10704 KB Output is correct
7 Correct 52 ms 10856 KB Output is correct
8 Correct 53 ms 10804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2560 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2560 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2656 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2788 KB Output is correct
17 Correct 23 ms 5712 KB Output is correct
18 Correct 23 ms 6300 KB Output is correct
19 Correct 22 ms 6204 KB Output is correct
20 Correct 22 ms 6244 KB Output is correct
21 Correct 21 ms 6208 KB Output is correct
22 Correct 43 ms 9648 KB Output is correct
23 Correct 6 ms 3476 KB Output is correct
24 Correct 16 ms 4988 KB Output is correct
25 Correct 2 ms 2756 KB Output is correct
26 Correct 7 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2560 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2656 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2788 KB Output is correct
17 Correct 23 ms 5712 KB Output is correct
18 Correct 23 ms 6300 KB Output is correct
19 Correct 22 ms 6204 KB Output is correct
20 Correct 22 ms 6244 KB Output is correct
21 Correct 21 ms 6208 KB Output is correct
22 Correct 43 ms 9648 KB Output is correct
23 Correct 6 ms 3476 KB Output is correct
24 Correct 16 ms 4988 KB Output is correct
25 Correct 2 ms 2756 KB Output is correct
26 Correct 7 ms 3408 KB Output is correct
27 Correct 3 ms 2848 KB Output is correct
28 Correct 114 ms 17848 KB Output is correct
29 Correct 148 ms 22412 KB Output is correct
30 Correct 151 ms 23252 KB Output is correct
31 Correct 153 ms 23272 KB Output is correct
32 Correct 142 ms 24060 KB Output is correct
33 Correct 150 ms 23388 KB Output is correct
34 Correct 144 ms 23256 KB Output is correct
35 Correct 55 ms 11056 KB Output is correct
36 Correct 144 ms 24436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 30 ms 7108 KB Output is correct
4 Correct 24 ms 5640 KB Output is correct
5 Correct 48 ms 10552 KB Output is correct
6 Correct 44 ms 10704 KB Output is correct
7 Correct 52 ms 10856 KB Output is correct
8 Correct 53 ms 10804 KB Output is correct
9 Correct 45 ms 10548 KB Output is correct
10 Correct 45 ms 9804 KB Output is correct
11 Correct 100 ms 17000 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 3 ms 2648 KB Output is correct
20 Correct 2 ms 2648 KB Output is correct
21 Correct 3 ms 2648 KB Output is correct
22 Correct 53 ms 10148 KB Output is correct
23 Correct 94 ms 17044 KB Output is correct
24 Correct 99 ms 17432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10556 KB Output is correct
2 Correct 45 ms 11724 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 143 ms 26440 KB Output is correct
6 Correct 150 ms 24616 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 78 ms 15848 KB Output is correct
9 Correct 101 ms 19196 KB Output is correct
10 Correct 37 ms 10040 KB Output is correct
11 Correct 44 ms 11316 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 37 ms 10612 KB Output is correct
19 Correct 46 ms 12480 KB Output is correct
20 Correct 41 ms 9472 KB Output is correct
21 Correct 47 ms 11060 KB Output is correct
22 Correct 44 ms 9432 KB Output is correct
23 Correct 44 ms 10408 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 30 ms 7108 KB Output is correct
27 Correct 24 ms 5640 KB Output is correct
28 Correct 48 ms 10552 KB Output is correct
29 Correct 44 ms 10704 KB Output is correct
30 Correct 52 ms 10856 KB Output is correct
31 Correct 53 ms 10804 KB Output is correct
32 Correct 1 ms 2560 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 3 ms 2900 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2772 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 3 ms 2656 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2788 KB Output is correct
48 Correct 23 ms 5712 KB Output is correct
49 Correct 23 ms 6300 KB Output is correct
50 Correct 22 ms 6204 KB Output is correct
51 Correct 22 ms 6244 KB Output is correct
52 Correct 21 ms 6208 KB Output is correct
53 Correct 43 ms 9648 KB Output is correct
54 Correct 6 ms 3476 KB Output is correct
55 Correct 16 ms 4988 KB Output is correct
56 Correct 2 ms 2756 KB Output is correct
57 Correct 7 ms 3408 KB Output is correct
58 Correct 3 ms 2848 KB Output is correct
59 Correct 114 ms 17848 KB Output is correct
60 Correct 148 ms 22412 KB Output is correct
61 Correct 151 ms 23252 KB Output is correct
62 Correct 153 ms 23272 KB Output is correct
63 Correct 142 ms 24060 KB Output is correct
64 Correct 150 ms 23388 KB Output is correct
65 Correct 144 ms 23256 KB Output is correct
66 Correct 55 ms 11056 KB Output is correct
67 Correct 144 ms 24436 KB Output is correct
68 Correct 45 ms 10548 KB Output is correct
69 Correct 45 ms 9804 KB Output is correct
70 Correct 100 ms 17000 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 1 ms 2644 KB Output is correct
73 Correct 1 ms 2644 KB Output is correct
74 Correct 2 ms 2644 KB Output is correct
75 Correct 2 ms 2648 KB Output is correct
76 Correct 1 ms 2648 KB Output is correct
77 Correct 2 ms 2648 KB Output is correct
78 Correct 3 ms 2648 KB Output is correct
79 Correct 2 ms 2648 KB Output is correct
80 Correct 3 ms 2648 KB Output is correct
81 Correct 53 ms 10148 KB Output is correct
82 Correct 94 ms 17044 KB Output is correct
83 Correct 99 ms 17432 KB Output is correct
84 Correct 157 ms 22836 KB Output is correct
85 Correct 152 ms 23116 KB Output is correct
86 Correct 155 ms 24124 KB Output is correct
87 Correct 152 ms 24300 KB Output is correct
88 Correct 2 ms 2648 KB Output is correct
89 Correct 155 ms 24320 KB Output is correct
90 Correct 150 ms 24116 KB Output is correct
91 Correct 140 ms 23836 KB Output is correct