제출 #1199941

#제출 시각아이디문제언어결과실행 시간메모리
1199941fadyscube메기 농장 (IOI22_fish)C++17
컴파일 에러
0 ms0 KiB
#include "fish.h"

#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    ll can1 = 0;
    ll can2 = 0;
    for (int i = 0; i < M; i++) {
        if (X[i] == 0)
            can2 += W[i];
        else
            can1 += W[i];
    }

    if (N <= 2) {
        return max(can1, can2);
    } else {
        vector<pair<int, int>> v;
        for (int i = 0; i < M; i++) {
            v.push_back({Y[i], i});
        }
        struct {
            bool operator()(pair<int, int> a, pair<int, int> b) const {
                if (a.first == b.first) return X[a.second] < X[b.second];
                return a.first < b.first;
            }
        }
        customLess;
        sort(v.begin(), v.end(), customLess);
        ll tmp = can1;
        for (int i = 0; i < M;) {
            int j = v[i].second;
            if (i+1 < M && v[i].first == v[i+1].first) {
                tmp -= W[j];
                tmp += W[v[i+1].second];
                i += 2;
            } else if (X[j] == 0) {
                tmp += W[j];
                i++;
            } else {
                tmp -= W[j];
                i++;
            }
            can1 = max(tmp, can1);
        }

        return can1;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

fish.cpp: In member function 'bool max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)::<unnamed struct>::operator()(std::pair<int, int>, std::pair<int, int>) const':
fish.cpp:29:48: error: use of parameter from containing function
   29 |                 if (a.first == b.first) return X[a.second] < X[b.second];
      |                                                ^
fish.cpp:10:49: note: 'std::vector<int> X' declared here
   10 | long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
      |                                     ~~~~~~~~~~~~^
fish.cpp:29:62: error: use of parameter from containing function
   29 |                 if (a.first == b.first) return X[a.second] < X[b.second];
      |                                                              ^
fish.cpp:10:49: note: 'std::vector<int> X' declared here
   10 | long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
      |                                     ~~~~~~~~~~~~^