Submission #786857

# Submission time Handle Problem Language Result Execution time Memory
786857 2023-07-18T13:56:35 Z andrei_boaca Catfish Farm (IOI22_fish) C++17
100 / 100
156 ms 33424 KB
#include "fish.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
ll n,m;
struct date
{
    ll poz,val;
};
vector<date> myy[100005];
ll dp[3][2][100005];
bool comp(date a, date b)
{
    return a.poz<b.poz;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    n=N;
    m=M;
    for(int i=0;i<m;i++)
    {
        ll x=X[i];
        ll y=Y[i];
        ll w=W[i];
        myy[x+1].push_back({y+1,w});
    }
    for(int i=1;i<=n;i++)
    {
        myy[i].push_back({0,0});
        myy[i].push_back({n+1,0});
        sort(myy[i].begin(),myy[i].end(),comp);
    }
    ll ans=0;
    ll cur=1;
    ll prv=0;
    for(int i=2;i<=n;i++)
    {
        // neutru
        ll suma=0;
        vector<ll> suf;
        int lg=myy[i-1].size();
        ll maxim=0;
        for(int j=lg-1;j>=0;j--)
        {
            int p1=myy[i-1][j].poz-1;
            maxim=max(maxim,max(dp[1][prv][p1],dp[2][prv][p1]));
            suf.push_back(maxim);
        }
        reverse(suf.begin(),suf.end());
        for(ll j=0;j<myy[i].size();j++)
        {
            suma+=myy[i][j].val;
            ll p=myy[i][j].poz;
            dp[0][cur][p]=0;
            ll st=0;
            ll dr=myy[i-1].size();
            dr--;
            while(st<=dr)
            {
                ll mij=(st+dr)/2;
                if(myy[i-1][mij].poz-1>=p)
                {
                    dp[0][cur][p]=max(dp[0][cur][p],suma+suf[mij]);
                    dr=mij-1;
                }
                else
                    st=mij+1;
            }
            ans=max(ans,dp[0][cur][p]);
        }
        vector<ll> prefsum;
        suma=0;
        for(int j=0;j<myy[i-1].size();j++)
        {
            suma+=myy[i-1][j].val;
            prefsum.push_back(suma);
        }
        maxim=0;
        ll s2=0;
        for(ll k=0;k<myy[i-1].size();k++)
        {
            ll poz=myy[i-1][k].poz-1;
            if(poz>=0)
            {
                ll val=dp[1][prv][poz]-s2;
                maxim=max(maxim,val);
            }
            s2+=myy[i-1][k].val;
            poz++;
            ll val=dp[0][prv][poz]-s2;
            maxim=max(maxim,val);
        }
        // cresc
        for(int j=0;j<myy[i].size();j++)
        {
            ll p=myy[i][j].poz-1;
            if(p<0)
                continue;
            dp[1][cur][p]=0;
            ll s1=0;
            ll st=0;
            ll dr=myy[i-1].size();
            dr--;
            while(st<=dr)
            {
                ll mij=(st+dr)/2;
                if(myy[i-1][mij].poz<=p)
                {
                    s1=prefsum[mij];
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            dp[1][cur][p]=s1+maxim;
            ans=max(ans,dp[1][cur][p]);
        }

        // desc
        prefsum.clear();
        suma=0;
        for(int j=0;j<myy[i].size();j++)
        {
            suma+=myy[i][j].val;
            prefsum.push_back(suma);
        }
        maxim=0;
        for(int k=0;k<myy[i-1].size();k++)
        {
            ll p1=myy[i-1][k].poz-1;
            if(p1<0)
                continue;
            ll s1=0;
            ll st=0;
            ll dr=myy[i].size();
            dr--;
            while(st<=dr)
            {
                ll mij=(st+dr)/2;
                if(myy[i][mij].poz<=p1)
                {
                    s1=prefsum[mij];
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            ll val=max(dp[1][prv][p1],dp[2][prv][p1])+s1;
            maxim=max(maxim,val);
        }
        s2=0;
        for(int j=0;j<myy[i].size();j++)
        {
            ll p=myy[i][j].poz-1;
            if(p<0)
                continue;
            ll poz=0;
            dp[2][cur][p]=maxim-s2;
            ans=max(ans,dp[2][cur][p]);
            s2+=myy[i][j].val;
        }
        swap(cur,prv);
    }
    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:50:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(ll j=0;j<myy[i].size();j++)
      |                    ~^~~~~~~~~~~~~~
fish.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int j=0;j<myy[i-1].size();j++)
      |                     ~^~~~~~~~~~~~~~~~
fish.cpp:80:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(ll k=0;k<myy[i-1].size();k++)
      |                    ~^~~~~~~~~~~~~~~~
fish.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int j=0;j<myy[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
fish.cpp:122:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |         for(int j=0;j<myy[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
fish.cpp:128:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         for(int k=0;k<myy[i-1].size();k++)
      |                     ~^~~~~~~~~~~~~~~~
fish.cpp:152:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |         for(int j=0;j<myy[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
fish.cpp:157:16: warning: unused variable 'poz' [-Wunused-variable]
  157 |             ll poz=0;
      |                ^~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 12356 KB Output is correct
2 Correct 57 ms 15612 KB Output is correct
3 Correct 21 ms 7380 KB Output is correct
4 Correct 21 ms 7332 KB Output is correct
5 Correct 132 ms 30288 KB Output is correct
6 Correct 150 ms 30736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 87 ms 17664 KB Output is correct
3 Correct 107 ms 23608 KB Output is correct
4 Correct 47 ms 13772 KB Output is correct
5 Correct 55 ms 15532 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 20 ms 7256 KB Output is correct
11 Correct 20 ms 7380 KB Output is correct
12 Correct 48 ms 15884 KB Output is correct
13 Correct 58 ms 17896 KB Output is correct
14 Correct 48 ms 13736 KB Output is correct
15 Correct 58 ms 14888 KB Output is correct
16 Correct 51 ms 13716 KB Output is correct
17 Correct 54 ms 14820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 7380 KB Output is correct
2 Correct 20 ms 7304 KB Output is correct
3 Correct 46 ms 11308 KB Output is correct
4 Correct 43 ms 10200 KB Output is correct
5 Correct 59 ms 15080 KB Output is correct
6 Correct 68 ms 14652 KB Output is correct
7 Correct 60 ms 15072 KB Output is correct
8 Correct 59 ms 15144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 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 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 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 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 19 ms 4680 KB Output is correct
18 Correct 18 ms 5196 KB Output is correct
19 Correct 16 ms 5112 KB Output is correct
20 Correct 16 ms 5112 KB Output is correct
21 Correct 17 ms 5116 KB Output is correct
22 Correct 32 ms 7580 KB Output is correct
23 Correct 5 ms 3156 KB Output is correct
24 Correct 12 ms 4052 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 4 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 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 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 19 ms 4680 KB Output is correct
18 Correct 18 ms 5196 KB Output is correct
19 Correct 16 ms 5112 KB Output is correct
20 Correct 16 ms 5112 KB Output is correct
21 Correct 17 ms 5116 KB Output is correct
22 Correct 32 ms 7580 KB Output is correct
23 Correct 5 ms 3156 KB Output is correct
24 Correct 12 ms 4052 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 4 ms 3028 KB Output is correct
27 Correct 3 ms 3028 KB Output is correct
28 Correct 93 ms 13640 KB Output is correct
29 Correct 127 ms 17044 KB Output is correct
30 Correct 110 ms 16532 KB Output is correct
31 Correct 132 ms 16528 KB Output is correct
32 Correct 131 ms 18324 KB Output is correct
33 Correct 111 ms 16536 KB Output is correct
34 Correct 112 ms 16520 KB Output is correct
35 Correct 42 ms 8524 KB Output is correct
36 Correct 121 ms 18504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 7380 KB Output is correct
2 Correct 20 ms 7304 KB Output is correct
3 Correct 46 ms 11308 KB Output is correct
4 Correct 43 ms 10200 KB Output is correct
5 Correct 59 ms 15080 KB Output is correct
6 Correct 68 ms 14652 KB Output is correct
7 Correct 60 ms 15072 KB Output is correct
8 Correct 59 ms 15144 KB Output is correct
9 Correct 79 ms 19584 KB Output is correct
10 Correct 47 ms 11216 KB Output is correct
11 Correct 99 ms 19912 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 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 22 ms 7364 KB Output is correct
19 Correct 20 ms 7260 KB Output is correct
20 Correct 20 ms 7384 KB Output is correct
21 Correct 21 ms 7308 KB Output is correct
22 Correct 68 ms 18996 KB Output is correct
23 Correct 99 ms 19872 KB Output is correct
24 Correct 93 ms 20600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 12356 KB Output is correct
2 Correct 57 ms 15612 KB Output is correct
3 Correct 21 ms 7380 KB Output is correct
4 Correct 21 ms 7332 KB Output is correct
5 Correct 132 ms 30288 KB Output is correct
6 Correct 150 ms 30736 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 87 ms 17664 KB Output is correct
9 Correct 107 ms 23608 KB Output is correct
10 Correct 47 ms 13772 KB Output is correct
11 Correct 55 ms 15532 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 20 ms 7256 KB Output is correct
17 Correct 20 ms 7380 KB Output is correct
18 Correct 48 ms 15884 KB Output is correct
19 Correct 58 ms 17896 KB Output is correct
20 Correct 48 ms 13736 KB Output is correct
21 Correct 58 ms 14888 KB Output is correct
22 Correct 51 ms 13716 KB Output is correct
23 Correct 54 ms 14820 KB Output is correct
24 Correct 20 ms 7380 KB Output is correct
25 Correct 20 ms 7304 KB Output is correct
26 Correct 46 ms 11308 KB Output is correct
27 Correct 43 ms 10200 KB Output is correct
28 Correct 59 ms 15080 KB Output is correct
29 Correct 68 ms 14652 KB Output is correct
30 Correct 60 ms 15072 KB Output is correct
31 Correct 59 ms 15144 KB Output is correct
32 Correct 1 ms 2644 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 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 1 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 2 ms 2772 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2772 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 2 ms 2772 KB Output is correct
48 Correct 19 ms 4680 KB Output is correct
49 Correct 18 ms 5196 KB Output is correct
50 Correct 16 ms 5112 KB Output is correct
51 Correct 16 ms 5112 KB Output is correct
52 Correct 17 ms 5116 KB Output is correct
53 Correct 32 ms 7580 KB Output is correct
54 Correct 5 ms 3156 KB Output is correct
55 Correct 12 ms 4052 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 4 ms 3028 KB Output is correct
58 Correct 3 ms 3028 KB Output is correct
59 Correct 93 ms 13640 KB Output is correct
60 Correct 127 ms 17044 KB Output is correct
61 Correct 110 ms 16532 KB Output is correct
62 Correct 132 ms 16528 KB Output is correct
63 Correct 131 ms 18324 KB Output is correct
64 Correct 111 ms 16536 KB Output is correct
65 Correct 112 ms 16520 KB Output is correct
66 Correct 42 ms 8524 KB Output is correct
67 Correct 121 ms 18504 KB Output is correct
68 Correct 79 ms 19584 KB Output is correct
69 Correct 47 ms 11216 KB Output is correct
70 Correct 99 ms 19912 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 1 ms 2644 KB Output is correct
75 Correct 2 ms 2644 KB Output is correct
76 Correct 2 ms 2652 KB Output is correct
77 Correct 22 ms 7364 KB Output is correct
78 Correct 20 ms 7260 KB Output is correct
79 Correct 20 ms 7384 KB Output is correct
80 Correct 21 ms 7308 KB Output is correct
81 Correct 68 ms 18996 KB Output is correct
82 Correct 99 ms 19872 KB Output is correct
83 Correct 93 ms 20600 KB Output is correct
84 Correct 151 ms 29608 KB Output is correct
85 Correct 156 ms 30044 KB Output is correct
86 Correct 153 ms 32368 KB Output is correct
87 Correct 148 ms 33228 KB Output is correct
88 Correct 2 ms 2644 KB Output is correct
89 Correct 156 ms 33424 KB Output is correct
90 Correct 134 ms 26628 KB Output is correct
91 Correct 149 ms 26700 KB Output is correct