답안 #1078728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078728 2024-08-28T05:16:35 Z LittleOrange 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
#include "fish.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
                      std::vector<int> w) {
  ll sub1 = 1, sub2 = 1, sub3 = 1;
  n++;
  vector<vector<pair<ll,ll>>> a(n);
  vector<vector<ll>> b(n);
  for(ll i = 0;i<m;i++){
    a[x[i]].push_back({y[i],w[i]});
    if(x[i]) b[x[i]-1].push_back(y[i]);
    b[x[i]+1].push_back(y[i]);
    if(x[i]&1) sub1 = 0;
    if(x[i]>1) sub2 = 0;
    if(y[i]) sub3 = 0;
  }
  for(auto &o : a) sort(o.begin(),o.end());
  for(auto &o : b) sort(o.begin(),o.end());
  if (sub1){
    ll ans = 0;
    for(ll i : w) ans += i;
    return ans;
  }
  if(sub2){
    ll a1 = 0, a2 = 0;
    for(auto [p,v] : a[0]) a1+=v;
    for(auto [p,v] : a[1]) a2+=v;
    return max(a1,a2);
  }
  if (sub3){
    vector<ll> dp(n+1,0);
    for(ll i = 0;i<n;i++){
      dp[i+1] = dp[i];
      if(b[i].size()){
        ll v = b[i][0].second;
        if (i>0) v += dp[i-1];
        dp[i+1] = max(dp[i+1],v);
      }
    }
    return dp.back();
  }
  return 0;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:40:24: error: request for member 'second' in '(& b.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](0)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
   40 |         ll v = b[i][0].second;
      |                        ^~~~~~