Submission #682475

# Submission time Handle Problem Language Result Execution time Memory
682475 2023-01-16T09:19:49 Z Jarif_Rahman Catfish Farm (IOI22_fish) C++17
53 / 100
975 ms 158680 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W){
    vector<vector<pair<int, ll>>> v(n);
    map<pair<int, int>, ll> mp;
    for(int i = 0; i < n; i++) mp[{i, 0}] = 0;
    for(int i = 0; i < n; i++) mp[{i, n+1}] = 0;
    for(int i = 0; i < m; i++){
        mp[{X[i], Y[i]+1}]+=W[i];
        if(X[i]) mp[{X[i]-1, Y[i]+1}]+=0;
        if(X[i]+1 < n) mp[{X[i]+1, Y[i]+1}]+=0;
    }

    for(auto [p, w]: mp) v[p.f].pb({p.sc, w});

    vector<vector<ll>> dp_up(n), dp_down, dtu2, pref;
    vector<ll> dtu(n, 0);

    for(int i = 0; i < n; i++) dp_up[i].resize(v[i].size(), 0);
    dp_down = dp_up;
    dtu2 = dp_up;
    pref = dp_up;

    for(int i = 0; i < n; i++) for(int j = 0; j < pref[i].size(); j++){
        if(j) pref[i][j] = pref[i][j-1];
        pref[i][j]+=v[i][j].sc;
    }

    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j < v[i].size(); j++){
            if(i == n-1){
                dp_down[i][j] = 0;
                dp_up[i][j] = 0;
                continue;
            }

            int in1 = lower_bound(v[i+1].begin(), v[i+1].end(), make_pair(v[i][j].f, -1LL))-v[i+1].begin();
            if(in1 == v[i+1].size()) in1--;

            dp_up[i][j]-=pref[i][j];
            dp_down[i][j]-=pref[i+1].back()-pref[i+1][in1];
            dp_up[i][j] = max(dp_up[i][j], pref[i].back()-pref[i][j]+dp_down[i+1].back());

            if(i+2 < n){
                int in2 = lower_bound(v[i+2].begin(), v[i+2].end(), make_pair(v[i][j].f, -1LL))-v[i+2].begin();
                if(in2 == v[i+2].size()) in2--;
                dp_down[i][j] = max(dp_down[i][j], dtu2[i+2][in2]+pref[i+1][in1]);
                dp_down[i][j] = max(dp_down[i][j], dtu[i+2]-pref[i+1][in1]);
                dp_down[i][j] = max(dp_down[i][j], pref[i+1].back()+dp_down[i+2].back());
            }
        }

        if(i){
            ll mx = 0, s = 0;
            auto it = v[i-1].begin();
            for(int j = 0; j < v[i].size(); j++){
                while(it != v[i-1].end() && it->f <= v[i][j].f) s+=it->sc, it++;
                mx = max(mx, s+dp_up[i][j]);
            }
            fill(dp_up[i-1].begin(), dp_up[i-1].end(), mx);
            dtu[i] = mx;

            mx = 0;
            for(int j = 0; j < v[i].size(); j++) mx = max(mx, pref[i].back()-pref[i][j]+dp_down[i][j]);
            fill(dp_down[i-1].begin(), dp_down[i-1].end(), mx);

            for(int j = 0; j < v[i].size(); j++){
                if(j) dtu2[i][j] = dtu2[i][j-1];
                dtu2[i][j] = max(dtu2[i][j], dp_up[i][j]);
            }
        }
    }

    return max(*max_element(dp_up[0].begin(), dp_up[0].end()), *max_element(dp_down[0].begin(), dp_down[0].end()));
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:30:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < n; i++) for(int j = 0; j < pref[i].size(); j++){
      |                                               ~~^~~~~~~~~~~~~~~~
fish.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j = 0; j < v[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
fish.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             if(in1 == v[i+1].size()) in1--;
      |                ~~~~^~~~~~~~~~~~~~~~
fish.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 if(in2 == v[i+2].size()) in2--;
      |                    ~~~~^~~~~~~~~~~~~~~~
fish.cpp:62:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for(int j = 0; j < v[i].size(); j++){
      |                            ~~^~~~~~~~~~~~~
fish.cpp:70:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int j = 0; j < v[i].size(); j++) mx = max(mx, pref[i].back()-pref[i][j]+dp_down[i][j]);
      |                            ~~^~~~~~~~~~~~~
fish.cpp:73:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             for(int j = 0; j < v[i].size(); j++){
      |                            ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 224 ms 58032 KB Output is correct
2 Correct 254 ms 66744 KB Output is correct
3 Correct 95 ms 42444 KB Output is correct
4 Correct 99 ms 42544 KB Output is correct
5 Correct 956 ms 148304 KB Output is correct
6 Correct 967 ms 158680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 392 ms 70524 KB Output is correct
3 Correct 470 ms 80324 KB Output is correct
4 Correct 208 ms 57948 KB Output is correct
5 Correct 254 ms 66832 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 94 ms 42504 KB Output is correct
11 Correct 96 ms 42484 KB Output is correct
12 Correct 285 ms 66868 KB Output is correct
13 Correct 346 ms 77756 KB Output is correct
14 Correct 248 ms 62536 KB Output is correct
15 Correct 238 ms 60436 KB Output is correct
16 Correct 259 ms 62544 KB Output is correct
17 Correct 276 ms 69304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 42444 KB Output is correct
2 Correct 97 ms 42556 KB Output is correct
3 Correct 157 ms 45084 KB Output is correct
4 Correct 144 ms 47572 KB Output is correct
5 Correct 237 ms 54308 KB Output is correct
6 Correct 261 ms 54200 KB Output is correct
7 Correct 248 ms 54248 KB Output is correct
8 Correct 247 ms 54316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 53 ms 8768 KB Output is correct
18 Correct 53 ms 7624 KB Output is correct
19 Correct 49 ms 7920 KB Output is correct
20 Correct 46 ms 6872 KB Output is correct
21 Correct 46 ms 6772 KB Output is correct
22 Correct 107 ms 13380 KB Output is correct
23 Correct 13 ms 3412 KB Output is correct
24 Correct 43 ms 8236 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 11 ms 2964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 53 ms 8768 KB Output is correct
18 Correct 53 ms 7624 KB Output is correct
19 Correct 49 ms 7920 KB Output is correct
20 Correct 46 ms 6872 KB Output is correct
21 Correct 46 ms 6772 KB Output is correct
22 Correct 107 ms 13380 KB Output is correct
23 Correct 13 ms 3412 KB Output is correct
24 Correct 43 ms 8236 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 11 ms 2964 KB Output is correct
27 Correct 6 ms 2676 KB Output is correct
28 Correct 452 ms 36828 KB Output is correct
29 Correct 774 ms 62700 KB Output is correct
30 Incorrect 975 ms 112096 KB 1st lines differ - on the 1st token, expected: '102439236138254', found: '102440153599307'
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 42444 KB Output is correct
2 Correct 97 ms 42556 KB Output is correct
3 Correct 157 ms 45084 KB Output is correct
4 Correct 144 ms 47572 KB Output is correct
5 Correct 237 ms 54308 KB Output is correct
6 Correct 261 ms 54200 KB Output is correct
7 Correct 248 ms 54248 KB Output is correct
8 Correct 247 ms 54316 KB Output is correct
9 Correct 324 ms 79352 KB Output is correct
10 Correct 181 ms 34648 KB Output is correct
11 Correct 454 ms 69180 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 98 ms 42564 KB Output is correct
19 Correct 99 ms 42540 KB Output is correct
20 Correct 95 ms 42500 KB Output is correct
21 Correct 98 ms 42536 KB Output is correct
22 Correct 383 ms 78452 KB Output is correct
23 Incorrect 579 ms 90632 KB 1st lines differ - on the 1st token, expected: '77772396150817', found: '77782926777237'
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 224 ms 58032 KB Output is correct
2 Correct 254 ms 66744 KB Output is correct
3 Correct 95 ms 42444 KB Output is correct
4 Correct 99 ms 42544 KB Output is correct
5 Correct 956 ms 148304 KB Output is correct
6 Correct 967 ms 158680 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 392 ms 70524 KB Output is correct
9 Correct 470 ms 80324 KB Output is correct
10 Correct 208 ms 57948 KB Output is correct
11 Correct 254 ms 66832 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 94 ms 42504 KB Output is correct
17 Correct 96 ms 42484 KB Output is correct
18 Correct 285 ms 66868 KB Output is correct
19 Correct 346 ms 77756 KB Output is correct
20 Correct 248 ms 62536 KB Output is correct
21 Correct 238 ms 60436 KB Output is correct
22 Correct 259 ms 62544 KB Output is correct
23 Correct 276 ms 69304 KB Output is correct
24 Correct 99 ms 42444 KB Output is correct
25 Correct 97 ms 42556 KB Output is correct
26 Correct 157 ms 45084 KB Output is correct
27 Correct 144 ms 47572 KB Output is correct
28 Correct 237 ms 54308 KB Output is correct
29 Correct 261 ms 54200 KB Output is correct
30 Correct 248 ms 54248 KB Output is correct
31 Correct 247 ms 54316 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 53 ms 8768 KB Output is correct
49 Correct 53 ms 7624 KB Output is correct
50 Correct 49 ms 7920 KB Output is correct
51 Correct 46 ms 6872 KB Output is correct
52 Correct 46 ms 6772 KB Output is correct
53 Correct 107 ms 13380 KB Output is correct
54 Correct 13 ms 3412 KB Output is correct
55 Correct 43 ms 8236 KB Output is correct
56 Correct 2 ms 724 KB Output is correct
57 Correct 11 ms 2964 KB Output is correct
58 Correct 6 ms 2676 KB Output is correct
59 Correct 452 ms 36828 KB Output is correct
60 Correct 774 ms 62700 KB Output is correct
61 Incorrect 975 ms 112096 KB 1st lines differ - on the 1st token, expected: '102439236138254', found: '102440153599307'
62 Halted 0 ms 0 KB -