Submission #629830

# Submission time Handle Problem Language Result Execution time Memory
629830 2022-08-15T08:31:31 Z Vovamatrix Catfish Farm (IOI22_fish) C++17
61 / 100
1000 ms 26404 KB
//https://oj.uz/problem/view/IOI22_fish
#include "fish.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define endl "\n"
 
#define all(data)       data.begin(),data.end()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()
#define ima_li_te(D,d)  find(all(D),d)
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
    vector<pair<int,ll>> v[n];
    ll dp[2][3][n+2],cnt=0;
    memset(dp,0,sizeof dp);
    for(int i=0;i<m;i++) y[i]++;
    for(int i=0;i<m;i++) v[x[i]].pb(mp(y[i],w[i]));
    for(int i=0;i<n;i++)
    {
        v[i].pb(mp(0,0)); sort(all(v[i])); v[i].pb(mp(n+2,0));
        for(int j=1;j<v[i].size();j++) v[i][j].sc+=v[i][j-1].sc;
    }
    for(int i=0;i<v[1].size();i++)
    {
        ll k=0;
        while(k+1<v[0].size() && v[1][i].fi>v[0][k+1].fi) k++;
        dp[1][2][i]=v[1].back().sc-v[1][max(i-1,0)].sc;
        dp[1][1][i]=v[0][k].sc;
    }
    for(int i=0;i<v[0].size();i++)
    {
        ll k=0;
        while(k+1<v[1].size() && v[0][i].fi>v[1][k+1].fi) k++;
        dp[1][0][i]=v[1][k].sc;
    }
    for(int i=2;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<max(v[i-1].size(),v[i].size());k++) dp[i&1][j][k]=0;
        }
        for(int j=0;j<v[i-1].size();j++)
        {
            ll k=0;
            while(k+1<v[i].size() && v[i-1][j].fi>v[i][k+1].fi) k++;
            dp[i&1][0][j]=max(dp[(i&1)^1][1][j],dp[(i&1)^1][2][j])+v[i][k].sc;
        }
        cnt=-1;
        for(int j=0;j<v[i].size();j++)
        {
            ll k=0,l=0,p=0;
            while(k<v[i-2].size() && v[i][j].fi>v[i-2][k].fi)
            {
                while(l<v[i-1].size()-1 && v[i-2][k].fi>v[i-1][l+1].fi) l++;
                cnt=max(cnt,dp[(i&1)^1][0][k]+v[i-1][l].sc);
                k++;
            }
            while(p<v[i-1].size()-1 && v[i][j].fi>v[i-1][p+1].fi) p++;
            dp[i&1][1][j]=max(dp[i&1][1][j],cnt-v[i-1][p].sc);
        }
        cnt=-1;
        for(int j=v[i].size()-1;j>=0;j--)
        {
            ll k=v[i-2].size()-1;
            while(k>=0 && v[i][j].fi<=v[i-2][k].fi)
            {
                cnt=max(cnt,dp[(i&1)^1][0][k]);
                k--;
            }
            dp[i&1][1][j]=max(dp[i&1][1][j],cnt);
        }
        cnt=-1;
        for(int j=0;j<v[i].size();j++)
        {
            ll k=0,l=0;
            while(k<v[i-1].size() && v[i][j].fi>=v[i-1][k].fi)
            {
                cnt=max(cnt, dp[(i&1)^1][1][k]-v[i-1][max(k-1,0ll)].sc);
                k++;
            }
            while(l<v[i-1].size()-1 && v[i][j].fi > v[i-1][l].fi) l++;
            dp[i&1][1][j]=max(dp[i&1][1][j],cnt+v[i-1][max(l-1,0ll)].sc);
        }
        cnt=-1;
        for(int j=v[i].size()-1;j>=0;j--)
        {
            ll k=v[i-1].size()-1,l=v[i].size()-1;
            while(k>=0 && v[i][j].fi<v[i-1][k].fi)
            {
                while(l>0 && v[i-1][k].fi<=v[i][l].fi) l--;
                cnt=max(cnt,max(dp[(i&1)^1][1][k],dp[(i&1)^1][2][k])+v[i][l].sc);
                k--;
            }
            dp[i&1][2][j]=max(dp[i&1][2][j],cnt-v[i][max(j-1,0)].sc);
        }
    }
    ll rez=0;
    for(int i=0;i<v[n-2].size();i++) rez=max(rez,dp[(n-1)&1][0][i]);
    for(int i=1;i<3;i++)
    {
        for(int j=0;j<v[n-1].size();j++) rez=max(rez,dp[(n-1)&1][i][j]);
    }
    return rez;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:35:22: 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]
   35 |         for(int j=1;j<v[i].size();j++) v[i][j].sc+=v[i][j-1].sc;
      |                     ~^~~~~~~~~~~~
fish.cpp:37:18: 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]
   37 |     for(int i=0;i<v[1].size();i++)
      |                 ~^~~~~~~~~~~~
fish.cpp:40:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         while(k+1<v[0].size() && v[1][i].fi>v[0][k+1].fi) k++;
      |               ~~~^~~~~~~~~~~~
fish.cpp:44:18: 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 |     for(int i=0;i<v[0].size();i++)
      |                 ~^~~~~~~~~~~~
fish.cpp:47:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         while(k+1<v[1].size() && v[0][i].fi>v[1][k+1].fi) k++;
      |               ~~~^~~~~~~~~~~~
fish.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   54 |             for(int k=0;k<max(v[i-1].size(),v[i].size());k++) dp[i&1][j][k]=0;
      |                         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:56:22: 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]
   56 |         for(int j=0;j<v[i-1].size();j++)
      |                     ~^~~~~~~~~~~~~~
fish.cpp:59:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             while(k+1<v[i].size() && v[i-1][j].fi>v[i][k+1].fi) k++;
      |                   ~~~^~~~~~~~~~~~
fish.cpp:63:22: 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]
   63 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
fish.cpp:66:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             while(k<v[i-2].size() && v[i][j].fi>v[i-2][k].fi)
      |                   ~^~~~~~~~~~~~~~
fish.cpp:68:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                 while(l<v[i-1].size()-1 && v[i-2][k].fi>v[i-1][l+1].fi) l++;
      |                       ~^~~~~~~~~~~~~~~~
fish.cpp:72:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             while(p<v[i-1].size()-1 && v[i][j].fi>v[i-1][p+1].fi) p++;
      |                   ~^~~~~~~~~~~~~~~~
fish.cpp:87:22: 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]
   87 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
fish.cpp:90:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |             while(k<v[i-1].size() && v[i][j].fi>=v[i-1][k].fi)
      |                   ~^~~~~~~~~~~~~~
fish.cpp:95:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             while(l<v[i-1].size()-1 && v[i][j].fi > v[i-1][l].fi) l++;
      |                   ~^~~~~~~~~~~~~~~~
fish.cpp:112:18: 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]
  112 |     for(int i=0;i<v[n-2].size();i++) rez=max(rez,dp[(n-1)&1][0][i]);
      |                 ~^~~~~~~~~~~~~~
fish.cpp:115:22: 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]
  115 |         for(int j=0;j<v[n-1].size();j++) rez=max(rez,dp[(n-1)&1][i][j]);
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 14012 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 21 ms 11928 KB Output is correct
4 Correct 20 ms 11992 KB Output is correct
5 Correct 140 ms 23748 KB Output is correct
6 Correct 152 ms 26404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1096 ms 17224 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 11988 KB Output is correct
2 Correct 20 ms 12028 KB Output is correct
3 Correct 39 ms 14188 KB Output is correct
4 Correct 34 ms 14268 KB Output is correct
5 Correct 61 ms 18192 KB Output is correct
6 Correct 60 ms 18116 KB Output is correct
7 Correct 60 ms 18240 KB Output is correct
8 Correct 64 ms 18124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 85 ms 2284 KB Output is correct
18 Correct 82 ms 2900 KB Output is correct
19 Correct 47 ms 2772 KB Output is correct
20 Correct 49 ms 2644 KB Output is correct
21 Correct 46 ms 2644 KB Output is correct
22 Correct 151 ms 5220 KB Output is correct
23 Correct 6 ms 724 KB Output is correct
24 Correct 39 ms 1800 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 85 ms 2284 KB Output is correct
18 Correct 82 ms 2900 KB Output is correct
19 Correct 47 ms 2772 KB Output is correct
20 Correct 49 ms 2644 KB Output is correct
21 Correct 46 ms 2644 KB Output is correct
22 Correct 151 ms 5220 KB Output is correct
23 Correct 6 ms 724 KB Output is correct
24 Correct 39 ms 1800 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 850 ms 11316 KB Output is correct
29 Execution timed out 1091 ms 14700 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 11988 KB Output is correct
2 Correct 20 ms 12028 KB Output is correct
3 Correct 39 ms 14188 KB Output is correct
4 Correct 34 ms 14268 KB Output is correct
5 Correct 61 ms 18192 KB Output is correct
6 Correct 60 ms 18116 KB Output is correct
7 Correct 60 ms 18240 KB Output is correct
8 Correct 64 ms 18124 KB Output is correct
9 Correct 62 ms 18176 KB Output is correct
10 Correct 52 ms 10636 KB Output is correct
11 Correct 114 ms 21036 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 0 ms 212 KB Output is correct
18 Correct 20 ms 11972 KB Output is correct
19 Correct 26 ms 12004 KB Output is correct
20 Correct 26 ms 11912 KB Output is correct
21 Correct 20 ms 11988 KB Output is correct
22 Correct 65 ms 16836 KB Output is correct
23 Correct 113 ms 21088 KB Output is correct
24 Correct 104 ms 21088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 14012 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 21 ms 11928 KB Output is correct
4 Correct 20 ms 11992 KB Output is correct
5 Correct 140 ms 23748 KB Output is correct
6 Correct 152 ms 26404 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Execution timed out 1096 ms 17224 KB Time limit exceeded
9 Halted 0 ms 0 KB -