답안 #1080544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080544 2024-08-29T10:51:24 Z Wansur 메기 농장 (IOI22_fish) C++17
100 / 100
392 ms 123016 KB
#include "fish.h"
#include <bits/stdc++.h>
#define ent '\n'

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;

vector<int> s[maxn];
vector<ll> dp[maxn], dpt[maxn], d[maxn];
vector<ll> pref[maxn], mx[maxn], suff[maxn];
vector<ll> a[maxn], mval[maxn];

long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    ll ans = 0;
    for(int i=0;i<m;i++){
        x[i]++, y[i]++;
        for(int d=-1;d<=1;d++){
            s[x[i] + d].push_back(y[i]);
        }
    }
    for(int i=0;i<=n;i++){
        s[i].push_back(0);
        sort(s[i].begin(), s[i].end());
        s[i].resize(unique(s[i].begin(), s[i].end()) - s[i].begin());
        dp[i] = d[i] = pref[i] = mx[i] = suff[i] = a[i] = mval[i] = vector<ll> ((int)s[i].size(), 0);
        dpt[i] = {0};
    }

    for(int i=0;i<m;i++){
        int j = lower_bound(s[x[i]].begin(), s[x[i]].end(), y[i]) - s[x[i]].begin();
        a[x[i]][j] += w[i];
    }
    for(int i=1;i<=n;i++){
        ll sum = 0;
        for(int j=0;j<s[i].size();j++){
            sum += a[i][j];
            pref[i][j] = sum;
        }
    }

    for(int i=1;i<=n;i++){
        dpt[i] = vector<ll> (s[i-1].size(), 0);
        ll val = -1e18;

        for(int j=0;j<(int)s[i].size();j++){
            int x = s[i][j];
            int it = upper_bound(s[i-1].begin(), s[i-1].end(), x) - s[i-1].begin();
            it--;

            dp[i][j] = max(mx[i-1][it] + pref[i-1][it], mval[i-1][it]);
            d[i][j] = max(dp[i][j], suff[i-1][it] - pref[i][j]);
            val = max(val, d[i][j]);
            mval[i][j] = val;
            ans = max(ans, d[i][j]);
        }

        for(int j=0;j<(int)s[i-1].size();j++){
            int x = s[i-1][j];
            int it = upper_bound(s[i].begin(), s[i].end(), x) - s[i].begin();
            it--;
            dpt[i][j] = d[i-1][j] + pref[i][it];
        }

        val = -1e18;

        for(int j=0;j<(int)s[i].size();j++){
            int x = s[i][j];
            int it = upper_bound(s[i-1].begin(), s[i-1].end(), x) - s[i-1].begin();
            it--;

            val = max(val, max(dp[i][j], dpt[i][it]) - pref[i][j]);
            mx[i][j] = val;
        }

        val = -1e18;

        if(i < n){
            for(int j=(int)s[i].size() - 1;j>=0;j--){
                int x = s[i][j];
                int it = upper_bound(s[i+1].begin(), s[i+1].end(), x) - s[i+1].begin();
                it--;

                val = max(val, d[i][j] + pref[i+1][it]);
                suff[i][j] = val;
            }
        }
    }
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j=0;j<s[i].size();j++){
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 66288 KB Output is correct
2 Correct 157 ms 73820 KB Output is correct
3 Correct 60 ms 49488 KB Output is correct
4 Correct 54 ms 49628 KB Output is correct
5 Correct 372 ms 123016 KB Output is correct
6 Correct 317 ms 117120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 21336 KB Output is correct
2 Correct 192 ms 76692 KB Output is correct
3 Correct 228 ms 85344 KB Output is correct
4 Correct 125 ms 66248 KB Output is correct
5 Correct 150 ms 73668 KB Output is correct
6 Correct 9 ms 21336 KB Output is correct
7 Correct 10 ms 21340 KB Output is correct
8 Correct 9 ms 21340 KB Output is correct
9 Correct 9 ms 21340 KB Output is correct
10 Correct 53 ms 49492 KB Output is correct
11 Correct 50 ms 49496 KB Output is correct
12 Correct 162 ms 66500 KB Output is correct
13 Correct 155 ms 73668 KB Output is correct
14 Correct 129 ms 66296 KB Output is correct
15 Correct 135 ms 66452 KB Output is correct
16 Correct 133 ms 66404 KB Output is correct
17 Correct 144 ms 71236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 49580 KB Output is correct
2 Correct 53 ms 49488 KB Output is correct
3 Correct 74 ms 48976 KB Output is correct
4 Correct 88 ms 51032 KB Output is correct
5 Correct 93 ms 53492 KB Output is correct
6 Correct 102 ms 53012 KB Output is correct
7 Correct 87 ms 53640 KB Output is correct
8 Correct 89 ms 53584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 21340 KB Output is correct
2 Correct 9 ms 21340 KB Output is correct
3 Correct 10 ms 21340 KB Output is correct
4 Correct 12 ms 21496 KB Output is correct
5 Correct 13 ms 21340 KB Output is correct
6 Correct 9 ms 21336 KB Output is correct
7 Correct 11 ms 21536 KB Output is correct
8 Correct 11 ms 21336 KB Output is correct
9 Correct 11 ms 21580 KB Output is correct
10 Correct 12 ms 21848 KB Output is correct
11 Correct 10 ms 21596 KB Output is correct
12 Correct 11 ms 21608 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 10 ms 21596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 21340 KB Output is correct
2 Correct 9 ms 21340 KB Output is correct
3 Correct 10 ms 21340 KB Output is correct
4 Correct 12 ms 21496 KB Output is correct
5 Correct 13 ms 21340 KB Output is correct
6 Correct 9 ms 21336 KB Output is correct
7 Correct 11 ms 21536 KB Output is correct
8 Correct 11 ms 21336 KB Output is correct
9 Correct 11 ms 21580 KB Output is correct
10 Correct 12 ms 21848 KB Output is correct
11 Correct 10 ms 21596 KB Output is correct
12 Correct 11 ms 21608 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 10 ms 21596 KB Output is correct
15 Correct 14 ms 21824 KB Output is correct
16 Correct 11 ms 21852 KB Output is correct
17 Correct 31 ms 27996 KB Output is correct
18 Correct 29 ms 27228 KB Output is correct
19 Correct 30 ms 27220 KB Output is correct
20 Correct 28 ms 26964 KB Output is correct
21 Correct 30 ms 26892 KB Output is correct
22 Correct 50 ms 32204 KB Output is correct
23 Correct 15 ms 23644 KB Output is correct
24 Correct 37 ms 27220 KB Output is correct
25 Correct 10 ms 21852 KB Output is correct
26 Correct 16 ms 23388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 21340 KB Output is correct
2 Correct 9 ms 21340 KB Output is correct
3 Correct 10 ms 21340 KB Output is correct
4 Correct 12 ms 21496 KB Output is correct
5 Correct 13 ms 21340 KB Output is correct
6 Correct 9 ms 21336 KB Output is correct
7 Correct 11 ms 21536 KB Output is correct
8 Correct 11 ms 21336 KB Output is correct
9 Correct 11 ms 21580 KB Output is correct
10 Correct 12 ms 21848 KB Output is correct
11 Correct 10 ms 21596 KB Output is correct
12 Correct 11 ms 21608 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 10 ms 21596 KB Output is correct
15 Correct 14 ms 21824 KB Output is correct
16 Correct 11 ms 21852 KB Output is correct
17 Correct 31 ms 27996 KB Output is correct
18 Correct 29 ms 27228 KB Output is correct
19 Correct 30 ms 27220 KB Output is correct
20 Correct 28 ms 26964 KB Output is correct
21 Correct 30 ms 26892 KB Output is correct
22 Correct 50 ms 32204 KB Output is correct
23 Correct 15 ms 23644 KB Output is correct
24 Correct 37 ms 27220 KB Output is correct
25 Correct 10 ms 21852 KB Output is correct
26 Correct 16 ms 23388 KB Output is correct
27 Correct 11 ms 22876 KB Output is correct
28 Correct 122 ms 50512 KB Output is correct
29 Correct 235 ms 69968 KB Output is correct
30 Correct 256 ms 94288 KB Output is correct
31 Correct 269 ms 94200 KB Output is correct
32 Correct 155 ms 57172 KB Output is correct
33 Correct 234 ms 95828 KB Output is correct
34 Correct 230 ms 95740 KB Output is correct
35 Correct 77 ms 44592 KB Output is correct
36 Correct 234 ms 85236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 49580 KB Output is correct
2 Correct 53 ms 49488 KB Output is correct
3 Correct 74 ms 48976 KB Output is correct
4 Correct 88 ms 51032 KB Output is correct
5 Correct 93 ms 53492 KB Output is correct
6 Correct 102 ms 53012 KB Output is correct
7 Correct 87 ms 53640 KB Output is correct
8 Correct 89 ms 53584 KB Output is correct
9 Correct 110 ms 68948 KB Output is correct
10 Correct 64 ms 40564 KB Output is correct
11 Correct 137 ms 59732 KB Output is correct
12 Correct 9 ms 21336 KB Output is correct
13 Correct 10 ms 21824 KB Output is correct
14 Correct 13 ms 21336 KB Output is correct
15 Correct 9 ms 21340 KB Output is correct
16 Correct 9 ms 21580 KB Output is correct
17 Correct 9 ms 21340 KB Output is correct
18 Correct 51 ms 49756 KB Output is correct
19 Correct 67 ms 49488 KB Output is correct
20 Correct 52 ms 49520 KB Output is correct
21 Correct 54 ms 49492 KB Output is correct
22 Correct 139 ms 66128 KB Output is correct
23 Correct 171 ms 77396 KB Output is correct
24 Correct 181 ms 79188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 66288 KB Output is correct
2 Correct 157 ms 73820 KB Output is correct
3 Correct 60 ms 49488 KB Output is correct
4 Correct 54 ms 49628 KB Output is correct
5 Correct 372 ms 123016 KB Output is correct
6 Correct 317 ms 117120 KB Output is correct
7 Correct 15 ms 21336 KB Output is correct
8 Correct 192 ms 76692 KB Output is correct
9 Correct 228 ms 85344 KB Output is correct
10 Correct 125 ms 66248 KB Output is correct
11 Correct 150 ms 73668 KB Output is correct
12 Correct 9 ms 21336 KB Output is correct
13 Correct 10 ms 21340 KB Output is correct
14 Correct 9 ms 21340 KB Output is correct
15 Correct 9 ms 21340 KB Output is correct
16 Correct 53 ms 49492 KB Output is correct
17 Correct 50 ms 49496 KB Output is correct
18 Correct 162 ms 66500 KB Output is correct
19 Correct 155 ms 73668 KB Output is correct
20 Correct 129 ms 66296 KB Output is correct
21 Correct 135 ms 66452 KB Output is correct
22 Correct 133 ms 66404 KB Output is correct
23 Correct 144 ms 71236 KB Output is correct
24 Correct 55 ms 49580 KB Output is correct
25 Correct 53 ms 49488 KB Output is correct
26 Correct 74 ms 48976 KB Output is correct
27 Correct 88 ms 51032 KB Output is correct
28 Correct 93 ms 53492 KB Output is correct
29 Correct 102 ms 53012 KB Output is correct
30 Correct 87 ms 53640 KB Output is correct
31 Correct 89 ms 53584 KB Output is correct
32 Correct 10 ms 21340 KB Output is correct
33 Correct 9 ms 21340 KB Output is correct
34 Correct 10 ms 21340 KB Output is correct
35 Correct 12 ms 21496 KB Output is correct
36 Correct 13 ms 21340 KB Output is correct
37 Correct 9 ms 21336 KB Output is correct
38 Correct 11 ms 21536 KB Output is correct
39 Correct 11 ms 21336 KB Output is correct
40 Correct 11 ms 21580 KB Output is correct
41 Correct 12 ms 21848 KB Output is correct
42 Correct 10 ms 21596 KB Output is correct
43 Correct 11 ms 21608 KB Output is correct
44 Correct 11 ms 21596 KB Output is correct
45 Correct 10 ms 21596 KB Output is correct
46 Correct 14 ms 21824 KB Output is correct
47 Correct 11 ms 21852 KB Output is correct
48 Correct 31 ms 27996 KB Output is correct
49 Correct 29 ms 27228 KB Output is correct
50 Correct 30 ms 27220 KB Output is correct
51 Correct 28 ms 26964 KB Output is correct
52 Correct 30 ms 26892 KB Output is correct
53 Correct 50 ms 32204 KB Output is correct
54 Correct 15 ms 23644 KB Output is correct
55 Correct 37 ms 27220 KB Output is correct
56 Correct 10 ms 21852 KB Output is correct
57 Correct 16 ms 23388 KB Output is correct
58 Correct 11 ms 22876 KB Output is correct
59 Correct 122 ms 50512 KB Output is correct
60 Correct 235 ms 69968 KB Output is correct
61 Correct 256 ms 94288 KB Output is correct
62 Correct 269 ms 94200 KB Output is correct
63 Correct 155 ms 57172 KB Output is correct
64 Correct 234 ms 95828 KB Output is correct
65 Correct 230 ms 95740 KB Output is correct
66 Correct 77 ms 44592 KB Output is correct
67 Correct 234 ms 85236 KB Output is correct
68 Correct 110 ms 68948 KB Output is correct
69 Correct 64 ms 40564 KB Output is correct
70 Correct 137 ms 59732 KB Output is correct
71 Correct 9 ms 21336 KB Output is correct
72 Correct 10 ms 21824 KB Output is correct
73 Correct 13 ms 21336 KB Output is correct
74 Correct 9 ms 21340 KB Output is correct
75 Correct 9 ms 21580 KB Output is correct
76 Correct 9 ms 21340 KB Output is correct
77 Correct 51 ms 49756 KB Output is correct
78 Correct 67 ms 49488 KB Output is correct
79 Correct 52 ms 49520 KB Output is correct
80 Correct 54 ms 49492 KB Output is correct
81 Correct 139 ms 66128 KB Output is correct
82 Correct 171 ms 77396 KB Output is correct
83 Correct 181 ms 79188 KB Output is correct
84 Correct 352 ms 113076 KB Output is correct
85 Correct 392 ms 114864 KB Output is correct
86 Correct 294 ms 114436 KB Output is correct
87 Correct 319 ms 116856 KB Output is correct
88 Correct 10 ms 21336 KB Output is correct
89 Correct 321 ms 116816 KB Output is correct
90 Correct 267 ms 105040 KB Output is correct
91 Correct 222 ms 89468 KB Output is correct