답안 #1036904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036904 2024-07-27T19:30:02 Z _8_8_ 메기 농장 (IOI22_fish) C++17
100 / 100
698 ms 209860 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5 + 12;
typedef long long ll;
int n,m;
vector<vector<vector<ll>>> dp(N);
vector<int> g[N],in[N],t[N];
map<int,int> a[N];
long long max_weights(int nn, int mm,vector<int> X, vector<int> Y,vector<int> W) {
    n = nn;
    m = mm;
    for(int i = 0;i < m;i++) {
        X[i]++;
        Y[i]++;
        g[X[i]].push_back(Y[i]);
        a[X[i]][Y[i]] = W[i];
    }
    for(int i = 0;i <= n;i++) {
        for(int j:g[i]) {
            in[i].push_back(j - 1);
            in[i].push_back(j);
        }
        for(int j:g[i+1]) { 
            in[i].push_back(j);
        }
        for(int j:g[i-1]) {
            in[i].push_back(j);
        }
        in[i].push_back(0);
        sort(in[i].begin(),in[i].end());
        in[i].resize(unique(in[i].begin(),in[i].end()) - in[i].begin());
        dp[i].resize((int)in[i].size());
        for(int j = 0;j < (int)in[i].size();j++) {
            t[i].push_back((a[i].count(in[i][j]) ? a[i][in[i][j]] : 0));
            dp[i][j].resize(2);
        }
    }
    //0 : L > R
    //1 : L < R
    for(int i = 2;i <= n;i++) {
        int j1 = 0;
        ll mx = -1e18,p_ = 0,_p = 0;
        for(int j = 0;j < (int)in[i].size();j++) {
            _p += a[i - 1][in[i][j]];
            while(j1 < (int)in[i - 1].size() && in[i - 1][j1] <= in[i][j]) {
                p_ += (a[i - 1].count(in[i - 1][j1]) ? a[i - 1][in[i - 1][j1]] : 0);
                mx = max(mx,dp[i - 1][j1][1] - p_);
                j1++;
            }
            dp[i][j][1] = max(dp[i - 1][0][0],_p + mx);
        }
        j1 = (int)in[i - 1].size() - 1;
        mx = -1e18;
        p_ = 0,_p = 0;
        for(int j = (int)in[i].size() - 1;j >= 0;j--) {
            while(j1 >= 0 && in[i - 1][j1] >= in[i][j]) {
                mx = max(mx,max(dp[i - 1][j1][0],dp[i - 1][j1][1]) - _p);
                _p += (a[i].count(in[i - 1][j1]) ? a[i][in[i - 1][j1]] : 0);
                j1--;
            }
            dp[i][j][0] = p_ + mx;
            p_ += t[i][j];
        }
    }
    ll res = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = 0;j < (int)in[i].size();j++) {
            res = max({res,dp[i][j][0],dp[i][j][1]});
        }
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 81520 KB Output is correct
2 Correct 147 ms 88268 KB Output is correct
3 Correct 39 ms 59732 KB Output is correct
4 Correct 40 ms 59740 KB Output is correct
5 Correct 567 ms 177588 KB Output is correct
6 Correct 449 ms 209492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 42720 KB Output is correct
2 Correct 225 ms 95916 KB Output is correct
3 Correct 257 ms 104776 KB Output is correct
4 Correct 128 ms 81356 KB Output is correct
5 Correct 146 ms 88264 KB Output is correct
6 Correct 18 ms 42584 KB Output is correct
7 Correct 21 ms 42468 KB Output is correct
8 Correct 18 ms 42588 KB Output is correct
9 Correct 17 ms 42584 KB Output is correct
10 Correct 38 ms 59740 KB Output is correct
11 Correct 39 ms 59740 KB Output is correct
12 Correct 159 ms 85700 KB Output is correct
13 Correct 194 ms 92868 KB Output is correct
14 Correct 137 ms 83788 KB Output is correct
15 Correct 142 ms 80992 KB Output is correct
16 Correct 141 ms 83656 KB Output is correct
17 Correct 154 ms 88152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 59736 KB Output is correct
2 Correct 39 ms 59740 KB Output is correct
3 Correct 103 ms 69208 KB Output is correct
4 Correct 68 ms 67668 KB Output is correct
5 Correct 112 ms 79520 KB Output is correct
6 Correct 103 ms 78820 KB Output is correct
7 Correct 111 ms 79440 KB Output is correct
8 Correct 109 ms 79440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 42592 KB Output is correct
2 Correct 18 ms 42588 KB Output is correct
3 Correct 18 ms 42724 KB Output is correct
4 Correct 18 ms 42588 KB Output is correct
5 Correct 19 ms 42588 KB Output is correct
6 Correct 17 ms 42588 KB Output is correct
7 Correct 18 ms 42588 KB Output is correct
8 Correct 17 ms 42584 KB Output is correct
9 Correct 19 ms 42764 KB Output is correct
10 Correct 19 ms 43100 KB Output is correct
11 Correct 19 ms 42844 KB Output is correct
12 Correct 19 ms 42844 KB Output is correct
13 Correct 18 ms 42584 KB Output is correct
14 Correct 19 ms 42828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 42592 KB Output is correct
2 Correct 18 ms 42588 KB Output is correct
3 Correct 18 ms 42724 KB Output is correct
4 Correct 18 ms 42588 KB Output is correct
5 Correct 19 ms 42588 KB Output is correct
6 Correct 17 ms 42588 KB Output is correct
7 Correct 18 ms 42588 KB Output is correct
8 Correct 17 ms 42584 KB Output is correct
9 Correct 19 ms 42764 KB Output is correct
10 Correct 19 ms 43100 KB Output is correct
11 Correct 19 ms 42844 KB Output is correct
12 Correct 19 ms 42844 KB Output is correct
13 Correct 18 ms 42584 KB Output is correct
14 Correct 19 ms 42828 KB Output is correct
15 Correct 19 ms 42844 KB Output is correct
16 Correct 23 ms 43096 KB Output is correct
17 Correct 60 ms 52128 KB Output is correct
18 Correct 60 ms 51540 KB Output is correct
19 Correct 56 ms 51796 KB Output is correct
20 Correct 53 ms 51028 KB Output is correct
21 Correct 53 ms 50768 KB Output is correct
22 Correct 98 ms 58960 KB Output is correct
23 Correct 35 ms 46496 KB Output is correct
24 Correct 53 ms 52304 KB Output is correct
25 Correct 20 ms 43100 KB Output is correct
26 Correct 26 ms 45864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 42592 KB Output is correct
2 Correct 18 ms 42588 KB Output is correct
3 Correct 18 ms 42724 KB Output is correct
4 Correct 18 ms 42588 KB Output is correct
5 Correct 19 ms 42588 KB Output is correct
6 Correct 17 ms 42588 KB Output is correct
7 Correct 18 ms 42588 KB Output is correct
8 Correct 17 ms 42584 KB Output is correct
9 Correct 19 ms 42764 KB Output is correct
10 Correct 19 ms 43100 KB Output is correct
11 Correct 19 ms 42844 KB Output is correct
12 Correct 19 ms 42844 KB Output is correct
13 Correct 18 ms 42584 KB Output is correct
14 Correct 19 ms 42828 KB Output is correct
15 Correct 19 ms 42844 KB Output is correct
16 Correct 23 ms 43096 KB Output is correct
17 Correct 60 ms 52128 KB Output is correct
18 Correct 60 ms 51540 KB Output is correct
19 Correct 56 ms 51796 KB Output is correct
20 Correct 53 ms 51028 KB Output is correct
21 Correct 53 ms 50768 KB Output is correct
22 Correct 98 ms 58960 KB Output is correct
23 Correct 35 ms 46496 KB Output is correct
24 Correct 53 ms 52304 KB Output is correct
25 Correct 20 ms 43100 KB Output is correct
26 Correct 26 ms 45864 KB Output is correct
27 Correct 22 ms 44380 KB Output is correct
28 Correct 275 ms 87016 KB Output is correct
29 Correct 421 ms 115712 KB Output is correct
30 Correct 553 ms 180796 KB Output is correct
31 Correct 555 ms 179628 KB Output is correct
32 Correct 327 ms 96596 KB Output is correct
33 Correct 593 ms 185340 KB Output is correct
34 Correct 624 ms 185324 KB Output is correct
35 Correct 182 ms 82512 KB Output is correct
36 Correct 533 ms 159908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 59736 KB Output is correct
2 Correct 39 ms 59740 KB Output is correct
3 Correct 103 ms 69208 KB Output is correct
4 Correct 68 ms 67668 KB Output is correct
5 Correct 112 ms 79520 KB Output is correct
6 Correct 103 ms 78820 KB Output is correct
7 Correct 111 ms 79440 KB Output is correct
8 Correct 109 ms 79440 KB Output is correct
9 Correct 139 ms 99488 KB Output is correct
10 Correct 91 ms 69456 KB Output is correct
11 Correct 180 ms 96080 KB Output is correct
12 Correct 19 ms 42584 KB Output is correct
13 Correct 18 ms 42588 KB Output is correct
14 Correct 18 ms 42728 KB Output is correct
15 Correct 25 ms 42588 KB Output is correct
16 Correct 19 ms 42588 KB Output is correct
17 Correct 19 ms 42584 KB Output is correct
18 Correct 43 ms 59736 KB Output is correct
19 Correct 47 ms 59828 KB Output is correct
20 Correct 42 ms 59728 KB Output is correct
21 Correct 41 ms 59728 KB Output is correct
22 Correct 159 ms 109396 KB Output is correct
23 Correct 227 ms 119128 KB Output is correct
24 Correct 303 ms 121428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 81520 KB Output is correct
2 Correct 147 ms 88268 KB Output is correct
3 Correct 39 ms 59732 KB Output is correct
4 Correct 40 ms 59740 KB Output is correct
5 Correct 567 ms 177588 KB Output is correct
6 Correct 449 ms 209492 KB Output is correct
7 Correct 17 ms 42720 KB Output is correct
8 Correct 225 ms 95916 KB Output is correct
9 Correct 257 ms 104776 KB Output is correct
10 Correct 128 ms 81356 KB Output is correct
11 Correct 146 ms 88264 KB Output is correct
12 Correct 18 ms 42584 KB Output is correct
13 Correct 21 ms 42468 KB Output is correct
14 Correct 18 ms 42588 KB Output is correct
15 Correct 17 ms 42584 KB Output is correct
16 Correct 38 ms 59740 KB Output is correct
17 Correct 39 ms 59740 KB Output is correct
18 Correct 159 ms 85700 KB Output is correct
19 Correct 194 ms 92868 KB Output is correct
20 Correct 137 ms 83788 KB Output is correct
21 Correct 142 ms 80992 KB Output is correct
22 Correct 141 ms 83656 KB Output is correct
23 Correct 154 ms 88152 KB Output is correct
24 Correct 40 ms 59736 KB Output is correct
25 Correct 39 ms 59740 KB Output is correct
26 Correct 103 ms 69208 KB Output is correct
27 Correct 68 ms 67668 KB Output is correct
28 Correct 112 ms 79520 KB Output is correct
29 Correct 103 ms 78820 KB Output is correct
30 Correct 111 ms 79440 KB Output is correct
31 Correct 109 ms 79440 KB Output is correct
32 Correct 23 ms 42592 KB Output is correct
33 Correct 18 ms 42588 KB Output is correct
34 Correct 18 ms 42724 KB Output is correct
35 Correct 18 ms 42588 KB Output is correct
36 Correct 19 ms 42588 KB Output is correct
37 Correct 17 ms 42588 KB Output is correct
38 Correct 18 ms 42588 KB Output is correct
39 Correct 17 ms 42584 KB Output is correct
40 Correct 19 ms 42764 KB Output is correct
41 Correct 19 ms 43100 KB Output is correct
42 Correct 19 ms 42844 KB Output is correct
43 Correct 19 ms 42844 KB Output is correct
44 Correct 18 ms 42584 KB Output is correct
45 Correct 19 ms 42828 KB Output is correct
46 Correct 19 ms 42844 KB Output is correct
47 Correct 23 ms 43096 KB Output is correct
48 Correct 60 ms 52128 KB Output is correct
49 Correct 60 ms 51540 KB Output is correct
50 Correct 56 ms 51796 KB Output is correct
51 Correct 53 ms 51028 KB Output is correct
52 Correct 53 ms 50768 KB Output is correct
53 Correct 98 ms 58960 KB Output is correct
54 Correct 35 ms 46496 KB Output is correct
55 Correct 53 ms 52304 KB Output is correct
56 Correct 20 ms 43100 KB Output is correct
57 Correct 26 ms 45864 KB Output is correct
58 Correct 22 ms 44380 KB Output is correct
59 Correct 275 ms 87016 KB Output is correct
60 Correct 421 ms 115712 KB Output is correct
61 Correct 553 ms 180796 KB Output is correct
62 Correct 555 ms 179628 KB Output is correct
63 Correct 327 ms 96596 KB Output is correct
64 Correct 593 ms 185340 KB Output is correct
65 Correct 624 ms 185324 KB Output is correct
66 Correct 182 ms 82512 KB Output is correct
67 Correct 533 ms 159908 KB Output is correct
68 Correct 139 ms 99488 KB Output is correct
69 Correct 91 ms 69456 KB Output is correct
70 Correct 180 ms 96080 KB Output is correct
71 Correct 19 ms 42584 KB Output is correct
72 Correct 18 ms 42588 KB Output is correct
73 Correct 18 ms 42728 KB Output is correct
74 Correct 25 ms 42588 KB Output is correct
75 Correct 19 ms 42588 KB Output is correct
76 Correct 19 ms 42584 KB Output is correct
77 Correct 43 ms 59736 KB Output is correct
78 Correct 47 ms 59828 KB Output is correct
79 Correct 42 ms 59728 KB Output is correct
80 Correct 41 ms 59728 KB Output is correct
81 Correct 159 ms 109396 KB Output is correct
82 Correct 227 ms 119128 KB Output is correct
83 Correct 303 ms 121428 KB Output is correct
84 Correct 698 ms 178188 KB Output is correct
85 Correct 646 ms 178420 KB Output is correct
86 Correct 456 ms 206676 KB Output is correct
87 Correct 458 ms 209860 KB Output is correct
88 Correct 18 ms 42588 KB Output is correct
89 Correct 477 ms 209840 KB Output is correct
90 Correct 373 ms 162056 KB Output is correct
91 Correct 319 ms 122664 KB Output is correct