Submission #1076292

# Submission time Handle Problem Language Result Execution time Memory
1076292 2024-08-26T12:37:09 Z Faisal_Saqib Catfish Farm (IOI22_fish) C++17
53 / 100
255 ms 81880 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
const int N=1e5+100;
vll pre[N];
ll sz[N];
vll dp[N][3];
vll possible[N];
vector<pair<ll,ll>> values[N];
ll solve(ll&n,ll&m,vll&x,vll&y,vll&w)
{
    ll ans=0;
    for(int j=0;j<m;j++)
    {
        values[x[j]].push_back({y[j]+1,w[j]});
        possible[x[j]].push_back(y[j]+1);
        possible[x[j]+1].push_back(y[j]+1);
        if(x[j]>0)
            possible[x[j]-1].push_back(y[j]+1);
        // cout<<"AT "<<x[j]<<' '<<y[j]+1<<endl;
    }
    for(int i=0;i<=n;i++)
    {
        possible[i].push_back(0);
        possible[i].push_back(n);
        sort(begin(possible[i]),end(possible[i]));
        sort(begin(values[i]),end(values[i]));
        sz[i]=possible[i].size();
        pre[i].resize(sz[i]+1,0);
        ll sm=0;
        int pp=0;
        int rp=0;
        for(auto&j:possible[i])
        {
            while(pp<values[i].size() and values[i][pp].first<=j)
            {
                sm+=values[i][pp].second;
                pp++;
            }
            pre[i][rp]=sm;
            rp++;
        }
        dp[i][0].resize(sz[i]+1,0);
        dp[i][1].resize(sz[i]+1,0);
    }
    for(int i=1;i<n;i++)
    {
        // ll sum=0;
        ll mx1=-2e18;
        ll mx2=-2e18;
        ll mx11=0,mx22=0;
        for(int k=0;k<sz[i-1];k++)
        {
            int hp=possible[i-1][k];
            mx11=max(mx11,dp[i-1][0][k]);
            mx1=max(mx1,dp[i-1][0][k]-pre[i-1][k]);
        }
        for(int k=0;k<sz[i-1];k++)
        {
            int hp=possible[i-1][k];
            mx22=max(mx22,dp[i-1][1][k]);
            auto index=lower_bound(all(possible[i]),hp);
            if(index!=end(possible[i]))
            {
                int ind=index-begin(possible[i]);
                mx2=max(mx2,dp[i-1][1][k]+pre[i][ind]);
            }
            mx2=max(mx2,mx22);
        }
        // cout<<"For "<<i<<' '<<mx1<<' '<<mx2<<' '<<mx11<<' '<<mx22<<endl;
        int pp=0;
        for(auto&h:possible[i])
        {
            auto index=lower_bound(all(possible[i-1]),h);
            // if(possible[i-1][index]!=h)
            // {
            //     cout<<"Fudge\n";
            //     cout<<i-1<<' '<<index<<' '<<h<<endl;
            //     for(auto jp:possible[i-1])
            //     {
            //         cout<<jp<<' ';
            //     }
            //     cout<<endl;
            // }
            if(index!=end(possible[i-1]))
            {
                int ind=index-begin(possible[i-1]);
                dp[i][0][pp]=max(dp[i][0][pp],mx1+pre[i-1][ind]);
                dp[i][1][pp]=max(dp[i][1][pp],mx1+pre[i-1][ind]);
            }
            else
            {
                dp[i][0][pp]=max(dp[i][0][pp],mx1);
                dp[i][1][pp]=max(dp[i][1][pp],mx1);
            }
            dp[i][1][pp]=max(dp[i][1][pp],mx2-pre[i][pp]);

            dp[i][0][pp]=max(dp[i][0][pp],mx11);
            dp[i][0][pp]=max(dp[i][0][pp],mx22);

            dp[i][1][pp]=max(dp[i][1][pp],mx11);
            dp[i][1][pp]=max(dp[i][1][pp],mx22);
            pp++;
        }
    }
    // cout<<"Then\n";
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<sz[i];j++)
        {
            ans=max(ans,dp[i][0][j]);
            ans=max(ans,dp[i][1][j]);
            // cout<<i<<' '<<possible[i][j]<<' '<<0<<' '<<dp[i][0][j]<<endl;
            // cout<<i<<' '<<possible[i][j]<<' '<<1<<' '<<dp[i][1][j]<<endl;
        }
    }
    return ans;
}
// long long max_weights(int N, int M, std::vector<ll> X, std::vector<ll> Y,std::vector<ll> W)
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W)
{
    ll n=N,m=M,ans=0;
    vector<ll> x(all(X)),y(all(Y)),w(all(W));
    return solve(n,m,x,y,w);
}

Compilation message

fish.cpp: In function 'long long int solve(long long int&, long long int&, std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)':
fish.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             while(pp<values[i].size() and values[i][pp].first<=j)
      |                   ~~^~~~~~~~~~~~~~~~~
fish.cpp:56:17: warning: unused variable 'hp' [-Wunused-variable]
   56 |             int hp=possible[i-1][k];
      |                 ^~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:124:16: warning: unused variable 'ans' [-Wunused-variable]
  124 |     ll n=N,m=M,ans=0;
      |                ^~~
# Verdict Execution time Memory Grader output
1 Correct 70 ms 36548 KB Output is correct
2 Correct 95 ms 40160 KB Output is correct
3 Correct 27 ms 27832 KB Output is correct
4 Correct 27 ms 27740 KB Output is correct
5 Correct 240 ms 76136 KB Output is correct
6 Correct 255 ms 81880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 126 ms 49300 KB Output is correct
3 Correct 155 ms 55816 KB Output is correct
4 Correct 66 ms 36544 KB Output is correct
5 Correct 80 ms 40388 KB Output is correct
6 Correct 9 ms 14424 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 5 ms 14364 KB Output is correct
10 Correct 27 ms 27824 KB Output is correct
11 Correct 26 ms 27740 KB Output is correct
12 Correct 89 ms 39624 KB Output is correct
13 Correct 96 ms 43712 KB Output is correct
14 Correct 76 ms 37824 KB Output is correct
15 Correct 86 ms 40540 KB Output is correct
16 Correct 76 ms 37932 KB Output is correct
17 Correct 87 ms 40360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 27740 KB Output is correct
2 Correct 27 ms 27740 KB Output is correct
3 Correct 55 ms 37784 KB Output is correct
4 Correct 46 ms 35712 KB Output is correct
5 Correct 109 ms 51076 KB Output is correct
6 Correct 95 ms 51028 KB Output is correct
7 Correct 85 ms 50980 KB Output is correct
8 Correct 93 ms 51028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 5 ms 14512 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 7 ms 14940 KB Output is correct
11 Correct 5 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 5 ms 14512 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 7 ms 14940 KB Output is correct
11 Correct 5 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14652 KB Output is correct
16 Correct 7 ms 14940 KB Output is correct
17 Correct 34 ms 22276 KB Output is correct
18 Correct 33 ms 22620 KB Output is correct
19 Correct 28 ms 22360 KB Output is correct
20 Correct 29 ms 22456 KB Output is correct
21 Correct 31 ms 22400 KB Output is correct
22 Correct 51 ms 30300 KB Output is correct
23 Correct 11 ms 16196 KB Output is correct
24 Correct 24 ms 20020 KB Output is correct
25 Correct 6 ms 14736 KB Output is correct
26 Correct 11 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 5 ms 14512 KB Output is correct
4 Correct 6 ms 14428 KB Output is correct
5 Correct 5 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 7 ms 14940 KB Output is correct
11 Correct 5 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 6 ms 14684 KB Output is correct
15 Correct 6 ms 14652 KB Output is correct
16 Correct 7 ms 14940 KB Output is correct
17 Correct 34 ms 22276 KB Output is correct
18 Correct 33 ms 22620 KB Output is correct
19 Correct 28 ms 22360 KB Output is correct
20 Correct 29 ms 22456 KB Output is correct
21 Correct 31 ms 22400 KB Output is correct
22 Correct 51 ms 30300 KB Output is correct
23 Correct 11 ms 16196 KB Output is correct
24 Correct 24 ms 20020 KB Output is correct
25 Correct 6 ms 14736 KB Output is correct
26 Correct 11 ms 15960 KB Output is correct
27 Correct 9 ms 15452 KB Output is correct
28 Correct 163 ms 51644 KB Output is correct
29 Correct 213 ms 65620 KB Output is correct
30 Incorrect 181 ms 69780 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 26 ms 27740 KB Output is correct
2 Correct 27 ms 27740 KB Output is correct
3 Correct 55 ms 37784 KB Output is correct
4 Correct 46 ms 35712 KB Output is correct
5 Correct 109 ms 51076 KB Output is correct
6 Correct 95 ms 51028 KB Output is correct
7 Correct 85 ms 50980 KB Output is correct
8 Correct 93 ms 51028 KB Output is correct
9 Correct 129 ms 51072 KB Output is correct
10 Correct 77 ms 37996 KB Output is correct
11 Correct 173 ms 61516 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14456 KB Output is correct
14 Correct 6 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14440 KB Output is correct
18 Correct 55 ms 27720 KB Output is correct
19 Correct 28 ms 27740 KB Output is correct
20 Correct 27 ms 27820 KB Output is correct
21 Correct 29 ms 27740 KB Output is correct
22 Correct 97 ms 47184 KB Output is correct
23 Incorrect 139 ms 61452 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 70 ms 36548 KB Output is correct
2 Correct 95 ms 40160 KB Output is correct
3 Correct 27 ms 27832 KB Output is correct
4 Correct 27 ms 27740 KB Output is correct
5 Correct 240 ms 76136 KB Output is correct
6 Correct 255 ms 81880 KB Output is correct
7 Correct 6 ms 14424 KB Output is correct
8 Correct 126 ms 49300 KB Output is correct
9 Correct 155 ms 55816 KB Output is correct
10 Correct 66 ms 36544 KB Output is correct
11 Correct 80 ms 40388 KB Output is correct
12 Correct 9 ms 14424 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14364 KB Output is correct
16 Correct 27 ms 27824 KB Output is correct
17 Correct 26 ms 27740 KB Output is correct
18 Correct 89 ms 39624 KB Output is correct
19 Correct 96 ms 43712 KB Output is correct
20 Correct 76 ms 37824 KB Output is correct
21 Correct 86 ms 40540 KB Output is correct
22 Correct 76 ms 37932 KB Output is correct
23 Correct 87 ms 40360 KB Output is correct
24 Correct 26 ms 27740 KB Output is correct
25 Correct 27 ms 27740 KB Output is correct
26 Correct 55 ms 37784 KB Output is correct
27 Correct 46 ms 35712 KB Output is correct
28 Correct 109 ms 51076 KB Output is correct
29 Correct 95 ms 51028 KB Output is correct
30 Correct 85 ms 50980 KB Output is correct
31 Correct 93 ms 51028 KB Output is correct
32 Correct 7 ms 14428 KB Output is correct
33 Correct 6 ms 14428 KB Output is correct
34 Correct 5 ms 14512 KB Output is correct
35 Correct 6 ms 14428 KB Output is correct
36 Correct 5 ms 14428 KB Output is correct
37 Correct 6 ms 14428 KB Output is correct
38 Correct 7 ms 14428 KB Output is correct
39 Correct 6 ms 14428 KB Output is correct
40 Correct 6 ms 14428 KB Output is correct
41 Correct 7 ms 14940 KB Output is correct
42 Correct 5 ms 14684 KB Output is correct
43 Correct 6 ms 14684 KB Output is correct
44 Correct 5 ms 14428 KB Output is correct
45 Correct 6 ms 14684 KB Output is correct
46 Correct 6 ms 14652 KB Output is correct
47 Correct 7 ms 14940 KB Output is correct
48 Correct 34 ms 22276 KB Output is correct
49 Correct 33 ms 22620 KB Output is correct
50 Correct 28 ms 22360 KB Output is correct
51 Correct 29 ms 22456 KB Output is correct
52 Correct 31 ms 22400 KB Output is correct
53 Correct 51 ms 30300 KB Output is correct
54 Correct 11 ms 16196 KB Output is correct
55 Correct 24 ms 20020 KB Output is correct
56 Correct 6 ms 14736 KB Output is correct
57 Correct 11 ms 15960 KB Output is correct
58 Correct 9 ms 15452 KB Output is correct
59 Correct 163 ms 51644 KB Output is correct
60 Correct 213 ms 65620 KB Output is correct
61 Incorrect 181 ms 69780 KB 1st lines differ - on the 1st token, expected: '102439236138254', found: '102440153599307'
62 Halted 0 ms 0 KB -