Submission #774045

# Submission time Handle Problem Language Result Execution time Memory
774045 2023-07-05T11:30:01 Z jasmin Catfish Farm (IOI22_fish) C++17
9 / 100
67 ms 41600 KB
#include "fish.h"
using namespace std;
#include<bits/stdc++.h>

#define ll long long


long long subtask1(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W){

    long long ans=0;
    for(int i=0; i<M; i++){
        ans+=W[i];
    }
    return ans;
}
long long subtask2(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W){
    
    vector<pair<int,int>> c0;
    vector<pair<int,int>> c1;
    long long sum0=0;
    long long sum1=0;
    for(int i=0; i<M; i++){

        if(X[i]==0){
            c0.push_back({Y[i], W[i]});
            sum0+=W[i];
        }
        else{
            c1.push_back({Y[i], W[i]});
            sum1+=W[i];
        }

    }
    
    if(N==2){
        return max(sum0, sum1);
    }

    sort(c1.begin(), c1.end());
    sort(c0.begin(), c0.end());
    long long ans=max(sum0, sum1);
    long long mom=sum1;
    int j=0;
    for(int i=0; i<(int)c1.size(); i++){

        while(j<(int)c0.size() && c0[j].first<c1[i].first){

            mom+=c0[j].second;
            j++;

        }

        ans=max(ans, mom);

        mom-=c1[i].second;
    }
    return ans;
}

long long gain(int h1, int free1, int h2, int free2, vector<pair<int,int> >& c1, vector<pair<int,int> >& c2){

    //wand von 1 ist grösser

    int wallh=c1[h1].first;

    ll ans=0;
    for(int i=max(h2, (int)c2.size()-free2); i<(int)c2.size(); i++){
        
        if(c2[i].first < wallh){
            ans+= c2[i].second;
        }
    }
    return ans;

}

const int INF=1e9+7;
long long subtask3(int n, int m, vector<int> x, vector<int> y, vector<int> w){

    vector<vector<pair<int,int> > > c(n);
    for(int i=0; i<m; i++){

        c[x[i]].push_back({y[i], w[i]});

    }
    int maxh=0;
    for(int i=0; i<n; i++){
        sort(c[i].begin(), c[i].end());
        c[i].push_back({INF, 0});

        maxh=max(maxh, (int)c[i].size());
    }


    vector<vector<vector<ll> > > dp(n, vector<vector<ll> > (maxh, vector<ll> (maxh)));
    for(int i=1; i<n; i++){

        for(int h=0; h<(int)c[i].size(); h++){
            for(int free=0; free<(int)c[i].size()-h; free++){


                for(int h0=0; h0<(int)c[i-1].size(); h0++){
                    for(int free0=0; free0<(int)c[i-1].size()-h0; free++){

                        
                        ll g=0;
                        if(c[i][h].first>c[i-1][h0].first){

                            g = gain(h, free, h0, free0, c[i], c[i-1]);

                        }
                        else{

                            g = gain(h0, free0, h, free, c[i-1], c[i]);
                        }

                        dp[i][h][free] = max(dp[i][h][free], dp[i-1][h0][free0] + g);

                    }
                }


            }
        }

    }

    ll ans=0;
    for(int h=0; h<maxh; h++){
        for(int free=0; free<maxh; free++){

            ans=max(ans, dp[n-1][h][free]);
        }
    }
    return ans;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {

    if(N==1) return 0;

    bool sub1=true;
    bool sub2=true;
    for(int i=0; i<M; i++){

        if(X[i]%2==1){
            sub1=false;
        }
        if(X[i]>1){
            sub2=false;
        }

    }

    if(sub1){
        return subtask1(N, M, X, Y, W);
    }
    if(sub2){
        return subtask2(N, M, X, Y, W);
    }


    return subtask3(N, M, X, Y, W);
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3028 KB Output is correct
2 Correct 23 ms 3700 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 65 ms 10732 KB Output is correct
6 Correct 67 ms 10852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 49 ms 7604 KB Output is correct
3 Correct 65 ms 9152 KB Output is correct
4 Correct 18 ms 3036 KB Output is correct
5 Correct 22 ms 3784 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 24 ms 4332 KB Output is correct
13 Correct 29 ms 4936 KB Output is correct
14 Correct 25 ms 4100 KB Output is correct
15 Correct 27 ms 4444 KB Output is correct
16 Correct 24 ms 4076 KB Output is correct
17 Correct 28 ms 4420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 37 ms 41600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 37 ms 41600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3028 KB Output is correct
2 Correct 23 ms 3700 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 65 ms 10732 KB Output is correct
6 Correct 67 ms 10852 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 49 ms 7604 KB Output is correct
9 Correct 65 ms 9152 KB Output is correct
10 Correct 18 ms 3036 KB Output is correct
11 Correct 22 ms 3784 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 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 1 ms 212 KB Output is correct
18 Correct 24 ms 4332 KB Output is correct
19 Correct 29 ms 4936 KB Output is correct
20 Correct 25 ms 4100 KB Output is correct
21 Correct 27 ms 4444 KB Output is correct
22 Correct 24 ms 4076 KB Output is correct
23 Correct 28 ms 4420 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Runtime error 37 ms 41600 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -