Submission #768072

# Submission time Handle Problem Language Result Execution time Memory
768072 2023-06-27T12:17:15 Z Khizri Catfish Farm (IOI22_fish) C++17
53 / 100
1000 ms 14336 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=3e5+5;
ll n,m,x[mxn],y[mxn],arr[mxn],val[305][305],pre[305][305],dp[305][305][2];
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n=N;
    m=M;
    bool t1=true,t2=true,t3=true;
    ll sum=0;
    for(int i=0;i<m;i++){
        x[i]=X[i];
        y[i]=Y[i];
        arr[i]=W[i];
        sum+=arr[i];
        if(x[i]%2) t1=false;
        if(x[i]>1) t2=false;
        if(y[i]!=0) t3=false;
    }
    if(t1){
        return sum;
    }
    if(t2){
        vector<int>a(n+5),b(n+5);
        ll k=0;
        for(int i=0;i<m;i++){
            if(x[i]==0){
                a[y[i]]=arr[i];
            }
            else{
                b[y[i]]=arr[i];
                k+=arr[i];
            }
        }
        if(n==2){
            return max(a[0]+a[1],b[0]+b[1]);
        }
        ll ans=k;
        for(int i=0;i<n;i++){
            k-=b[i];
            k+=a[i];
            ans=max(ans,k);
        }
        return ans;
    }
    if(t3){
        vector<vector<ll>>dp(n+5,vector<ll>(3));
        vector<ll>val(n+5);
        for(int i=0;i<m;i++){
            val[x[i]]=arr[i];
        }
        for(int i=1;i<n;i++){
            dp[i][1]=dp[i-1][1];
            if(i>1){
                dp[i][1]=max(dp[i-1][1],max(dp[i-2][1],dp[i-2][0])+val[i-1]);
            }
            else{
                dp[i][1]=val[i-1];
            }
            dp[i][0]=max(dp[i-1][0],dp[i-1][1]+val[i]);
        }
        return max(dp[n-1][1],dp[n-1][0]);
    }
    for(int i=0;i<m;i++){
        val[x[i]+1][y[i]+1]=arr[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            pre[j][i]=pre[j-1][i]+val[i][j];
        }
    }
    ll ans=0;
    for(int i=2;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<j;k++){
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][k][1]+pre[j][i-1]-pre[k][i-1]);
            }
            for(int k=0;k<=n&&i>1;k++){
                if(i==2){
                    dp[i][j][1]=pre[j][i-1];
                    dp[i][j][0]=pre[j][i-1];
                }
                else{
                    dp[i][j][1]=max(dp[i][j][1],max(dp[i-2][k][1],dp[i-2][k][0])+pre[max(k,j)][i-1]);
                    dp[i][j][0]=max(dp[i][j][0],max(dp[i-2][k][1],dp[i-2][k][0])+pre[max(k,j)][i-1]);
                }
            }
            for(int k=j;k<=n;k++){
                dp[i][j][0]=max(dp[i][j][0],max(dp[i-1][k][0],dp[i-1][k][1])+pre[k][i]-pre[j][i]);
            }
        }
    }
    for(int i=0;i<=n;i++){
        ans=max(ans,dp[n][i][0]);
        ans=max(ans,dp[n][i][1]);
    }
    return ans;
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
*/
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4052 KB Output is correct
2 Correct 23 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 71 ms 14336 KB Output is correct
6 Correct 77 ms 14320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 42 ms 8628 KB Output is correct
3 Correct 48 ms 10516 KB Output is correct
4 Correct 18 ms 4076 KB Output is correct
5 Correct 22 ms 4956 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 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 19 ms 4868 KB Output is correct
13 Correct 27 ms 5716 KB Output is correct
14 Correct 20 ms 4860 KB Output is correct
15 Correct 22 ms 5356 KB Output is correct
16 Correct 19 ms 4860 KB Output is correct
17 Correct 22 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 6484 KB Output is correct
3 Correct 18 ms 8404 KB Output is correct
4 Correct 14 ms 8276 KB Output is correct
5 Correct 29 ms 11216 KB Output is correct
6 Correct 26 ms 11232 KB Output is correct
7 Correct 27 ms 11220 KB Output is correct
8 Correct 30 ms 11220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 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 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 14 ms 1748 KB Output is correct
10 Correct 107 ms 3276 KB Output is correct
11 Correct 15 ms 1708 KB Output is correct
12 Correct 103 ms 3240 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 103 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 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 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 14 ms 1748 KB Output is correct
10 Correct 107 ms 3276 KB Output is correct
11 Correct 15 ms 1708 KB Output is correct
12 Correct 103 ms 3240 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 103 ms 3172 KB Output is correct
15 Correct 103 ms 3092 KB Output is correct
16 Correct 3 ms 1088 KB Output is correct
17 Correct 113 ms 5844 KB Output is correct
18 Correct 113 ms 5708 KB Output is correct
19 Correct 119 ms 6020 KB Output is correct
20 Correct 113 ms 6004 KB Output is correct
21 Correct 112 ms 5940 KB Output is correct
22 Correct 124 ms 8868 KB Output is correct
23 Correct 110 ms 3696 KB Output is correct
24 Correct 110 ms 5036 KB Output is correct
25 Correct 102 ms 3128 KB Output is correct
26 Correct 106 ms 3640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 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 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 14 ms 1748 KB Output is correct
10 Correct 107 ms 3276 KB Output is correct
11 Correct 15 ms 1708 KB Output is correct
12 Correct 103 ms 3240 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 103 ms 3172 KB Output is correct
15 Correct 103 ms 3092 KB Output is correct
16 Correct 3 ms 1088 KB Output is correct
17 Correct 113 ms 5844 KB Output is correct
18 Correct 113 ms 5708 KB Output is correct
19 Correct 119 ms 6020 KB Output is correct
20 Correct 113 ms 6004 KB Output is correct
21 Correct 112 ms 5940 KB Output is correct
22 Correct 124 ms 8868 KB Output is correct
23 Correct 110 ms 3696 KB Output is correct
24 Correct 110 ms 5036 KB Output is correct
25 Correct 102 ms 3128 KB Output is correct
26 Correct 106 ms 3640 KB Output is correct
27 Execution timed out 1088 ms 8448 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 6484 KB Output is correct
3 Correct 18 ms 8404 KB Output is correct
4 Correct 14 ms 8276 KB Output is correct
5 Correct 29 ms 11216 KB Output is correct
6 Correct 26 ms 11232 KB Output is correct
7 Correct 27 ms 11220 KB Output is correct
8 Correct 30 ms 11220 KB Output is correct
9 Runtime error 27 ms 9948 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4052 KB Output is correct
2 Correct 23 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 71 ms 14336 KB Output is correct
6 Correct 77 ms 14320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 42 ms 8628 KB Output is correct
9 Correct 48 ms 10516 KB Output is correct
10 Correct 18 ms 4076 KB Output is correct
11 Correct 22 ms 4956 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 340 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 340 KB Output is correct
18 Correct 19 ms 4868 KB Output is correct
19 Correct 27 ms 5716 KB Output is correct
20 Correct 20 ms 4860 KB Output is correct
21 Correct 22 ms 5356 KB Output is correct
22 Correct 19 ms 4860 KB Output is correct
23 Correct 22 ms 5208 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 6 ms 6484 KB Output is correct
26 Correct 18 ms 8404 KB Output is correct
27 Correct 14 ms 8276 KB Output is correct
28 Correct 29 ms 11216 KB Output is correct
29 Correct 26 ms 11232 KB Output is correct
30 Correct 27 ms 11220 KB Output is correct
31 Correct 30 ms 11220 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 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 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 14 ms 1748 KB Output is correct
41 Correct 107 ms 3276 KB Output is correct
42 Correct 15 ms 1708 KB Output is correct
43 Correct 103 ms 3240 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 103 ms 3172 KB Output is correct
46 Correct 103 ms 3092 KB Output is correct
47 Correct 3 ms 1088 KB Output is correct
48 Correct 113 ms 5844 KB Output is correct
49 Correct 113 ms 5708 KB Output is correct
50 Correct 119 ms 6020 KB Output is correct
51 Correct 113 ms 6004 KB Output is correct
52 Correct 112 ms 5940 KB Output is correct
53 Correct 124 ms 8868 KB Output is correct
54 Correct 110 ms 3696 KB Output is correct
55 Correct 110 ms 5036 KB Output is correct
56 Correct 102 ms 3128 KB Output is correct
57 Correct 106 ms 3640 KB Output is correct
58 Execution timed out 1088 ms 8448 KB Time limit exceeded
59 Halted 0 ms 0 KB -