답안 #626989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626989 2022-08-12T04:13:50 Z jhhope1 메기 농장 (IOI22_fish) C++17
12 / 100
142 ms 25376 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;
        }

        if(U.size()){
            T = max(T, U[0]);
            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()){
      |                            ~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 9648 KB Output is correct
2 Correct 59 ms 10844 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 140 ms 25376 KB Output is correct
6 Correct 142 ms 23664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 34 ms 6848 KB Output is correct
4 Correct 26 ms 5384 KB Output is correct
5 Correct 50 ms 10440 KB Output is correct
6 Correct 44 ms 10428 KB Output is correct
7 Correct 46 ms 10428 KB Output is correct
8 Correct 47 ms 10468 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 34 ms 6848 KB Output is correct
4 Correct 26 ms 5384 KB Output is correct
5 Correct 50 ms 10440 KB Output is correct
6 Correct 44 ms 10428 KB Output is correct
7 Correct 46 ms 10428 KB Output is correct
8 Correct 47 ms 10468 KB Output is correct
9 Incorrect 49 ms 10424 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 9648 KB Output is correct
2 Correct 59 ms 10844 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 140 ms 25376 KB Output is correct
6 Correct 142 ms 23664 KB Output is correct
7 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
8 Halted 0 ms 0 KB -