Submission #626987

# Submission time Handle Problem Language Result Execution time Memory
626987 2022-08-12T04:11:57 Z jhhope1 Catfish Farm (IOI22_fish) C++17
0 / 100
153 ms 48504 KB
#include <bits/stdc++.h>
#include "fish.h"

#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> tri;
const int MAXN = 100010;
const ll INF = 1e18;
vector<pii> HW[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    vector<tri> P;
    for(int i=0 ; i<M ; i++){
        P.emplace_back(pii(X[i], Y[i]), W[i]);
    }
    sort(P.begin(), P.end());
    for(int i=0 ; i<M ; i++){
        HW[P[i].first.first].emplace_back(P[i].first.second, P[i].second);
    }
    
    // initialization when i = 0
    vector<ll> U(HW[0].size(), 0), D(HW[0].size(), 0);
    ll T = 0, S = 0;
    for(int j=0 ; j<HW[0].size() ; j++){
        S += HW[0][j].second;
        D[j] = S;
    }

    for(int i=1 ; i<N ; i++){
        vector<ll> new_U(HW[i].size(), 0), new_D(HW[i].size(), 0);
        ll S = 0, ma = -INF;
        for(int j=HW[i].size()-1 ; j>=0 ; j--){
            S += HW[i][j].second;
            new_U[j] = T + S;
        }
        S = 0;
        for(int j=HW[i].size()-1 ; j>=0 ; j--){
            auto [x, w] = HW[i][j];
            int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x+1, 0)) - HW[i-1].begin();
            if(idx < HW[i-1].size()){
                ma = max(ma, U[idx] - S);
                new_U[j] = max(new_U[j], ma + (S + w));
            }
            S += w;
        }
        S = 0, ma = -INF;
        if(U.size()){
            for(int j=0 ; j<HW[i].size() ; j++){
                S += HW[i][j].second;
                new_D[j] = U[0] + S;
            }
        }
        S = 0;
        for(int j=0 ; j<HW[i].size() ; j++){
            auto [x, w] = HW[i][j];
            int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x-1, 0)) - HW[i-1].begin() - 1;
            if(idx >= 0 && idx < HW[i-1].size()){
                ma = max(ma, D[idx] - S);
                new_D[j] = max(new_D[j], ma + (S + w));
            }
            S += w;
        }

        T = max(T, U[0]);
        if(U.size()){
            T = max(T, D[D.size()-1]);
        }
        U = new_U;
        D = new_D;
    }
    if(U.size()){
        T = max(T, U[0]);
    }
    return T;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:25:20: 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]
   25 |     for(int j=0 ; j<HW[0].size() ; j++){
      |                   ~^~~~~~~~~~~~~
fish.cpp:41:20: 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]
   41 |             if(idx < HW[i-1].size()){
      |                ~~~~^~~~~~~~~~~~~~~~
fish.cpp:49:28: 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]
   49 |             for(int j=0 ; j<HW[i].size() ; j++){
      |                           ~^~~~~~~~~~~~~
fish.cpp:55:24: 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]
   55 |         for(int j=0 ; j<HW[i].size() ; j++){
      |                       ~^~~~~~~~~~~~~
fish.cpp:58:32: 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]
   58 |             if(idx >= 0 && idx < HW[i-1].size()){
      |                            ~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 34 ms 9736 KB Output is correct
2 Correct 41 ms 10932 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Runtime error 153 ms 48504 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2588 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Runtime error 3 ms 5076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Runtime error 3 ms 5076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 9736 KB Output is correct
2 Correct 41 ms 10932 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Runtime error 153 ms 48504 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -