답안 #629889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629889 2022-08-15T10:27:48 Z peti1234 메기 농장 (IOI22_fish) C++17
100 / 100
255 ms 235884 KB
#include <bits/stdc++.h>

using namespace std;
const int c=3000005;
int n, m, si[c];
vector<pair<int, int> > sz[c];
vector<long long> dp0[c], dp1[c];
// 0 - megkapta a felette levoket, 1 - meg nem kapta meg

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n=N, m=M;
    for (int i=0; i<m; i++) {
        int a=X[i], b=Y[i], s=W[i];
        a++, b++;
        sz[a].push_back({b, s});
        //cout << "alap " << a << " " << b << " " << s << "\n";
    }
    for (int i=1; i<=n; i++) {
        sz[i].push_back({n+1, 0});
        sort(sz[i].begin(), sz[i].end());
        si[i]=sz[i].size();
        dp0[i].resize(si[i]), dp1[i].resize(si[i]);
    }
    for (int i=1; i<=n; i++) {
        int x=si[i-1], y=si[i];

        // 0->1
        long long maxi=0, sum=0, pos=0;
        for (int j=0; j<x; j++) {
            maxi=max(maxi, dp0[i-1][j]);
        }
        for (int j=0; j<y; j++) {
            dp1[i][j]=maxi;
        }

        // 1->1
        maxi=0, sum=0;
        for (int j=0; j<x; j++) {
            maxi=max(maxi, dp1[i-1][j]-sum);
            sum+=sz[i-1][j].second;
        }
        sum=0;
        for (int j=0; j<y; j++) {
            while (pos<x && sz[i][j].first>sz[i-1][pos].first) {
                sum+=sz[i-1][pos].second;
                pos++;
            }
            dp1[i][j]=max(dp1[i][j], maxi+sum);
        }


        // 0->0
        maxi=0, sum=0, pos=0;
        for (int j=0; j<x; j++) {
            while (pos<y && sz[i-1][j].first>sz[i][pos].first) {
                sum+=sz[i][pos].second;
                pos++;
            }
            maxi=max(maxi, dp0[i-1][j]+sum);
        }
        sum=0;
        for (int j=0; j<y; j++) {
            dp0[i][j]=maxi-sum;
            sum+=sz[i][j].second;
        }


        // 1->0 olyan, csak rosszabb lehet, mint az 1->1
        for (int j=0; j<y; j++) {
            dp0[i][j]=max(dp0[i][j], dp1[i][j]);
        }

        for (int j=0; j<y; j++) {
            //cout << i << " " << j << " " << dp0[i][j] << " " << dp1[i][j] << "\n";
        }
    }

    long long maxi=0;
    for (int j=0; j<si[n]; j++) {
        maxi=max(maxi, dp0[n][j]);
    }
    return maxi;
}
/*
int main()
{
    int n, m;
    vector<int> a, b, c;
    cin >> n >> m;
    for (int i=0; i<m; i++) {
        int aa, bb, cc;
        cin >> aa >> bb >> cc;
        a.push_back(aa), b.push_back(bb), c.push_back(cc);
    }
    cout << max_weights(n, m, a, b, c) << "\n";
    return 0;
}
*/
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 224200 KB Output is correct
2 Correct 148 ms 226112 KB Output is correct
3 Correct 117 ms 221508 KB Output is correct
4 Correct 123 ms 221516 KB Output is correct
5 Correct 229 ms 235436 KB Output is correct
6 Correct 243 ms 234944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 211576 KB Output is correct
2 Correct 173 ms 228044 KB Output is correct
3 Correct 186 ms 230848 KB Output is correct
4 Correct 148 ms 224440 KB Output is correct
5 Correct 160 ms 226028 KB Output is correct
6 Correct 104 ms 211636 KB Output is correct
7 Correct 96 ms 211544 KB Output is correct
8 Correct 97 ms 211520 KB Output is correct
9 Correct 98 ms 211532 KB Output is correct
10 Correct 117 ms 221388 KB Output is correct
11 Correct 123 ms 221356 KB Output is correct
12 Correct 139 ms 224236 KB Output is correct
13 Correct 168 ms 226120 KB Output is correct
14 Correct 139 ms 224368 KB Output is correct
15 Correct 154 ms 225752 KB Output is correct
16 Correct 143 ms 224264 KB Output is correct
17 Correct 145 ms 225636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 221440 KB Output is correct
2 Correct 115 ms 221516 KB Output is correct
3 Correct 137 ms 221624 KB Output is correct
4 Correct 126 ms 222172 KB Output is correct
5 Correct 152 ms 223692 KB Output is correct
6 Correct 147 ms 223784 KB Output is correct
7 Correct 149 ms 223700 KB Output is correct
8 Correct 153 ms 223768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 211552 KB Output is correct
2 Correct 100 ms 211628 KB Output is correct
3 Correct 99 ms 211580 KB Output is correct
4 Correct 96 ms 211636 KB Output is correct
5 Correct 96 ms 211624 KB Output is correct
6 Correct 96 ms 211552 KB Output is correct
7 Correct 100 ms 211732 KB Output is correct
8 Correct 98 ms 211616 KB Output is correct
9 Correct 97 ms 211660 KB Output is correct
10 Correct 97 ms 211796 KB Output is correct
11 Correct 96 ms 211640 KB Output is correct
12 Correct 104 ms 211700 KB Output is correct
13 Correct 100 ms 211648 KB Output is correct
14 Correct 97 ms 211656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 211552 KB Output is correct
2 Correct 100 ms 211628 KB Output is correct
3 Correct 99 ms 211580 KB Output is correct
4 Correct 96 ms 211636 KB Output is correct
5 Correct 96 ms 211624 KB Output is correct
6 Correct 96 ms 211552 KB Output is correct
7 Correct 100 ms 211732 KB Output is correct
8 Correct 98 ms 211616 KB Output is correct
9 Correct 97 ms 211660 KB Output is correct
10 Correct 97 ms 211796 KB Output is correct
11 Correct 96 ms 211640 KB Output is correct
12 Correct 104 ms 211700 KB Output is correct
13 Correct 100 ms 211648 KB Output is correct
14 Correct 97 ms 211656 KB Output is correct
15 Correct 96 ms 211644 KB Output is correct
16 Correct 97 ms 211752 KB Output is correct
17 Correct 115 ms 213968 KB Output is correct
18 Correct 130 ms 214112 KB Output is correct
19 Correct 112 ms 214100 KB Output is correct
20 Correct 120 ms 213980 KB Output is correct
21 Correct 110 ms 214056 KB Output is correct
22 Correct 138 ms 216524 KB Output is correct
23 Correct 103 ms 212040 KB Output is correct
24 Correct 108 ms 213148 KB Output is correct
25 Correct 97 ms 211660 KB Output is correct
26 Correct 109 ms 212088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 211552 KB Output is correct
2 Correct 100 ms 211628 KB Output is correct
3 Correct 99 ms 211580 KB Output is correct
4 Correct 96 ms 211636 KB Output is correct
5 Correct 96 ms 211624 KB Output is correct
6 Correct 96 ms 211552 KB Output is correct
7 Correct 100 ms 211732 KB Output is correct
8 Correct 98 ms 211616 KB Output is correct
9 Correct 97 ms 211660 KB Output is correct
10 Correct 97 ms 211796 KB Output is correct
11 Correct 96 ms 211640 KB Output is correct
12 Correct 104 ms 211700 KB Output is correct
13 Correct 100 ms 211648 KB Output is correct
14 Correct 97 ms 211656 KB Output is correct
15 Correct 96 ms 211644 KB Output is correct
16 Correct 97 ms 211752 KB Output is correct
17 Correct 115 ms 213968 KB Output is correct
18 Correct 130 ms 214112 KB Output is correct
19 Correct 112 ms 214100 KB Output is correct
20 Correct 120 ms 213980 KB Output is correct
21 Correct 110 ms 214056 KB Output is correct
22 Correct 138 ms 216524 KB Output is correct
23 Correct 103 ms 212040 KB Output is correct
24 Correct 108 ms 213148 KB Output is correct
25 Correct 97 ms 211660 KB Output is correct
26 Correct 109 ms 212088 KB Output is correct
27 Correct 106 ms 211904 KB Output is correct
28 Correct 167 ms 223256 KB Output is correct
29 Correct 196 ms 227080 KB Output is correct
30 Correct 255 ms 226652 KB Output is correct
31 Correct 205 ms 226672 KB Output is correct
32 Correct 191 ms 228052 KB Output is correct
33 Correct 199 ms 226720 KB Output is correct
34 Correct 214 ms 226684 KB Output is correct
35 Correct 136 ms 217660 KB Output is correct
36 Correct 203 ms 227356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 221440 KB Output is correct
2 Correct 115 ms 221516 KB Output is correct
3 Correct 137 ms 221624 KB Output is correct
4 Correct 126 ms 222172 KB Output is correct
5 Correct 152 ms 223692 KB Output is correct
6 Correct 147 ms 223784 KB Output is correct
7 Correct 149 ms 223700 KB Output is correct
8 Correct 153 ms 223768 KB Output is correct
9 Correct 155 ms 223692 KB Output is correct
10 Correct 142 ms 219664 KB Output is correct
11 Correct 180 ms 227608 KB Output is correct
12 Correct 100 ms 211536 KB Output is correct
13 Correct 107 ms 211612 KB Output is correct
14 Correct 97 ms 211532 KB Output is correct
15 Correct 96 ms 211528 KB Output is correct
16 Correct 96 ms 211580 KB Output is correct
17 Correct 99 ms 211532 KB Output is correct
18 Correct 112 ms 221332 KB Output is correct
19 Correct 113 ms 221364 KB Output is correct
20 Correct 113 ms 221304 KB Output is correct
21 Correct 115 ms 221388 KB Output is correct
22 Correct 155 ms 224200 KB Output is correct
23 Correct 181 ms 227596 KB Output is correct
24 Correct 190 ms 227672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 224200 KB Output is correct
2 Correct 148 ms 226112 KB Output is correct
3 Correct 117 ms 221508 KB Output is correct
4 Correct 123 ms 221516 KB Output is correct
5 Correct 229 ms 235436 KB Output is correct
6 Correct 243 ms 234944 KB Output is correct
7 Correct 107 ms 211576 KB Output is correct
8 Correct 173 ms 228044 KB Output is correct
9 Correct 186 ms 230848 KB Output is correct
10 Correct 148 ms 224440 KB Output is correct
11 Correct 160 ms 226028 KB Output is correct
12 Correct 104 ms 211636 KB Output is correct
13 Correct 96 ms 211544 KB Output is correct
14 Correct 97 ms 211520 KB Output is correct
15 Correct 98 ms 211532 KB Output is correct
16 Correct 117 ms 221388 KB Output is correct
17 Correct 123 ms 221356 KB Output is correct
18 Correct 139 ms 224236 KB Output is correct
19 Correct 168 ms 226120 KB Output is correct
20 Correct 139 ms 224368 KB Output is correct
21 Correct 154 ms 225752 KB Output is correct
22 Correct 143 ms 224264 KB Output is correct
23 Correct 145 ms 225636 KB Output is correct
24 Correct 115 ms 221440 KB Output is correct
25 Correct 115 ms 221516 KB Output is correct
26 Correct 137 ms 221624 KB Output is correct
27 Correct 126 ms 222172 KB Output is correct
28 Correct 152 ms 223692 KB Output is correct
29 Correct 147 ms 223784 KB Output is correct
30 Correct 149 ms 223700 KB Output is correct
31 Correct 153 ms 223768 KB Output is correct
32 Correct 97 ms 211552 KB Output is correct
33 Correct 100 ms 211628 KB Output is correct
34 Correct 99 ms 211580 KB Output is correct
35 Correct 96 ms 211636 KB Output is correct
36 Correct 96 ms 211624 KB Output is correct
37 Correct 96 ms 211552 KB Output is correct
38 Correct 100 ms 211732 KB Output is correct
39 Correct 98 ms 211616 KB Output is correct
40 Correct 97 ms 211660 KB Output is correct
41 Correct 97 ms 211796 KB Output is correct
42 Correct 96 ms 211640 KB Output is correct
43 Correct 104 ms 211700 KB Output is correct
44 Correct 100 ms 211648 KB Output is correct
45 Correct 97 ms 211656 KB Output is correct
46 Correct 96 ms 211644 KB Output is correct
47 Correct 97 ms 211752 KB Output is correct
48 Correct 115 ms 213968 KB Output is correct
49 Correct 130 ms 214112 KB Output is correct
50 Correct 112 ms 214100 KB Output is correct
51 Correct 120 ms 213980 KB Output is correct
52 Correct 110 ms 214056 KB Output is correct
53 Correct 138 ms 216524 KB Output is correct
54 Correct 103 ms 212040 KB Output is correct
55 Correct 108 ms 213148 KB Output is correct
56 Correct 97 ms 211660 KB Output is correct
57 Correct 109 ms 212088 KB Output is correct
58 Correct 106 ms 211904 KB Output is correct
59 Correct 167 ms 223256 KB Output is correct
60 Correct 196 ms 227080 KB Output is correct
61 Correct 255 ms 226652 KB Output is correct
62 Correct 205 ms 226672 KB Output is correct
63 Correct 191 ms 228052 KB Output is correct
64 Correct 199 ms 226720 KB Output is correct
65 Correct 214 ms 226684 KB Output is correct
66 Correct 136 ms 217660 KB Output is correct
67 Correct 203 ms 227356 KB Output is correct
68 Correct 155 ms 223692 KB Output is correct
69 Correct 142 ms 219664 KB Output is correct
70 Correct 180 ms 227608 KB Output is correct
71 Correct 100 ms 211536 KB Output is correct
72 Correct 107 ms 211612 KB Output is correct
73 Correct 97 ms 211532 KB Output is correct
74 Correct 96 ms 211528 KB Output is correct
75 Correct 96 ms 211580 KB Output is correct
76 Correct 99 ms 211532 KB Output is correct
77 Correct 112 ms 221332 KB Output is correct
78 Correct 113 ms 221364 KB Output is correct
79 Correct 113 ms 221304 KB Output is correct
80 Correct 115 ms 221388 KB Output is correct
81 Correct 155 ms 224200 KB Output is correct
82 Correct 181 ms 227596 KB Output is correct
83 Correct 190 ms 227672 KB Output is correct
84 Correct 221 ms 235320 KB Output is correct
85 Correct 230 ms 235884 KB Output is correct
86 Correct 232 ms 232516 KB Output is correct
87 Correct 236 ms 233420 KB Output is correct
88 Correct 99 ms 211540 KB Output is correct
89 Correct 240 ms 233440 KB Output is correct
90 Correct 228 ms 235020 KB Output is correct
91 Correct 222 ms 235728 KB Output is correct