Submission #1075740

# Submission time Handle Problem Language Result Execution time Memory
1075740 2024-08-26T08:57:01 Z Muhammad_Aneeq Catfish Farm (IOI22_fish) C++17
53 / 100
1000 ms 284500 KB
#include <vector>
using namespace std;
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W)
{
    bool subt1=1,subt2=1,subt3=1,subt4=(N<=300);
    for (int i=0;i<M;i++)
    {
        if (X[i]%2)
            subt1=0;
        if (X[i]>1)
            subt2=0;
        if (Y[i]!=0)
            subt3=0;
        if (Y[i]>8)
            subt4=0;
    }
    if (subt1)
    {
        long long sm=0;
        for (int i=0;i<M;i++)
            sm+=W[i];
        return sm;
    }
    if (subt2)
    {
        long long sm[N]={};
        long long val[N][2]={};
        for (int i=0;i<M;i++)
            val[Y[i]][X[i]]=W[i];
        sm[0]=val[0][1];
        for (int i=1;i<N;i++)
            sm[i]=sm[i-1]+val[i][1];
        long long ans=sm[N-1];
        long long x=0;
        for (int i=0;i<N;i++)
        {
            x+=val[i][0];
            if (N>2)
                ans=max(ans,x+sm[N-1]-sm[i]);
        }
        ans=max(ans,x);
        return ans;
    }
    if (subt3)
    {
        long long dp[N][2]={};
        int val[N]={};
        for (int i=0;i<M;i++)
            val[X[i]]=W[i];
        dp[0][0]=0,dp[0][1]=val[0];
        long long ans=0;
        long long mx=0;
        for (int i=1;i<N;i++)
        {
            if (i>1)
                dp[i][0]=mx+val[i];
            if (i<N-1)
                dp[i][1]=max(dp[i][0],dp[i-1][0]+val[i]);
            mx=max(mx,max(dp[i-1][0],dp[i-1][1]));
            ans=max(ans,max(dp[i][0],dp[i][1]));
        }
        return ans;
    }
    if (N<=3000)
    {
        vector<vector<vector<long long>>>dp(2,vector<vector<long long>>(N+10,vector<long long>(N+10,0)));
        long long pre[N+10][N+10]={};
        for (int i=0;i<M;i++)
            pre[X[i]+1][Y[i]+1]=W[i];
        for (int i=1;i<=N;i++)
            for (int j=1;j<=N;j++)
                pre[i][j]+=pre[i][j-1];
        long long ans=0;
        for (int i=1;i<=N;i++)
            dp[0][0][i]=dp[1][0][i]=-1e17;;
        for (int i=1;i<=N;i++)
        {
            for (int j=0;j<=N;j++)
            {
                for (int k=0;k<=N;k++)
                {
                    if (j<k)
                    {
                        dp[0][i][j]=max(dp[0][i][j],dp[0][i-1][k]+pre[i][k]-pre[i][j]);
                        dp[1][i][k]=max(dp[1][i][k],dp[0][i-1][k]+pre[i][k]-pre[i][j]);
                    }
                    else
                    {
                        dp[0][i][j]=max(dp[0][i][j],dp[1][i-1][k]+pre[i-1][j]-pre[i-1][k]);
                        dp[1][i][j]=max(dp[1][i][j],dp[1][i-1][k]+pre[i-1][j]-pre[i-1][k]);
                    }
                }
                dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+pre[i][j]);
            }
        }
        for (int i=0;i<=N;i++)
                ans=max(ans,max(dp[0][N][i],dp[1][N][i]));
        return ans;
    }
    return 0;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:5:34: warning: variable 'subt4' set but not used [-Wunused-but-set-variable]
    5 |     bool subt1=1,subt2=1,subt3=1,subt4=(N<=300);
      |                                  ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2128 KB Output is correct
2 Correct 16 ms 2652 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 52 ms 7268 KB Output is correct
6 Correct 53 ms 7268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 34 ms 6176 KB Output is correct
3 Correct 38 ms 7388 KB Output is correct
4 Correct 13 ms 2140 KB Output is correct
5 Correct 16 ms 2632 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 16 ms 4444 KB Output is correct
13 Correct 37 ms 4920 KB Output is correct
14 Correct 15 ms 4444 KB Output is correct
15 Correct 16 ms 4700 KB Output is correct
16 Correct 16 ms 4400 KB Output is correct
17 Correct 34 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 11 ms 3356 KB Output is correct
4 Correct 8 ms 3164 KB Output is correct
5 Correct 19 ms 4684 KB Output is correct
6 Correct 16 ms 4700 KB Output is correct
7 Correct 17 ms 4700 KB Output is correct
8 Correct 35 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 7 ms 1112 KB Output is correct
10 Correct 45 ms 3420 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 46 ms 3420 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 45 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 7 ms 1112 KB Output is correct
10 Correct 45 ms 3420 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 46 ms 3420 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 45 ms 3416 KB Output is correct
15 Correct 46 ms 3420 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 54 ms 5212 KB Output is correct
18 Correct 54 ms 5208 KB Output is correct
19 Correct 53 ms 5268 KB Output is correct
20 Correct 61 ms 5272 KB Output is correct
21 Correct 54 ms 5208 KB Output is correct
22 Correct 62 ms 7076 KB Output is correct
23 Correct 46 ms 3928 KB Output is correct
24 Correct 50 ms 4444 KB Output is correct
25 Correct 43 ms 3420 KB Output is correct
26 Correct 45 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 7 ms 1112 KB Output is correct
10 Correct 45 ms 3420 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 46 ms 3420 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 45 ms 3416 KB Output is correct
15 Correct 46 ms 3420 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 54 ms 5212 KB Output is correct
18 Correct 54 ms 5208 KB Output is correct
19 Correct 53 ms 5268 KB Output is correct
20 Correct 61 ms 5272 KB Output is correct
21 Correct 54 ms 5208 KB Output is correct
22 Correct 62 ms 7076 KB Output is correct
23 Correct 46 ms 3928 KB Output is correct
24 Correct 50 ms 4444 KB Output is correct
25 Correct 43 ms 3420 KB Output is correct
26 Correct 45 ms 3672 KB Output is correct
27 Execution timed out 1073 ms 284500 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 11 ms 3356 KB Output is correct
4 Correct 8 ms 3164 KB Output is correct
5 Correct 19 ms 4684 KB Output is correct
6 Correct 16 ms 4700 KB Output is correct
7 Correct 17 ms 4700 KB Output is correct
8 Correct 35 ms 4700 KB Output is correct
9 Incorrect 16 ms 2648 KB 1st lines differ - on the 1st token, expected: '99999', found: '0'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2128 KB Output is correct
2 Correct 16 ms 2652 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 52 ms 7268 KB Output is correct
6 Correct 53 ms 7268 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 34 ms 6176 KB Output is correct
9 Correct 38 ms 7388 KB Output is correct
10 Correct 13 ms 2140 KB Output is correct
11 Correct 16 ms 2632 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 16 ms 4444 KB Output is correct
19 Correct 37 ms 4920 KB Output is correct
20 Correct 15 ms 4444 KB Output is correct
21 Correct 16 ms 4700 KB Output is correct
22 Correct 16 ms 4400 KB Output is correct
23 Correct 34 ms 4692 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 2140 KB Output is correct
26 Correct 11 ms 3356 KB Output is correct
27 Correct 8 ms 3164 KB Output is correct
28 Correct 19 ms 4684 KB Output is correct
29 Correct 16 ms 4700 KB Output is correct
30 Correct 17 ms 4700 KB Output is correct
31 Correct 35 ms 4700 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1112 KB Output is correct
41 Correct 45 ms 3420 KB Output is correct
42 Correct 10 ms 1112 KB Output is correct
43 Correct 46 ms 3420 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 45 ms 3416 KB Output is correct
46 Correct 46 ms 3420 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 54 ms 5212 KB Output is correct
49 Correct 54 ms 5208 KB Output is correct
50 Correct 53 ms 5268 KB Output is correct
51 Correct 61 ms 5272 KB Output is correct
52 Correct 54 ms 5208 KB Output is correct
53 Correct 62 ms 7076 KB Output is correct
54 Correct 46 ms 3928 KB Output is correct
55 Correct 50 ms 4444 KB Output is correct
56 Correct 43 ms 3420 KB Output is correct
57 Correct 45 ms 3672 KB Output is correct
58 Execution timed out 1073 ms 284500 KB Time limit exceeded
59 Halted 0 ms 0 KB -