제출 #871916

#제출 시각아이디문제언어결과실행 시간메모리
871916Ludissey메기 농장 (IOI22_fish)C++17
컴파일 에러
0 ms0 KiB
#include "fish.h" #include <bits/stdc++.h> #define int long long using namespace std; map<pair<int,int>, int> a; vector<vector<int>> fsh; map<pair<int,pair<int,int>>, int> memo; int N,M; int dp(int x, int last, int lastlast){ if(memo.find({x,{last,lastlast}})!=memo.end()) return memo[{x,{last,lastlast}}]; if(x==N) return 0; memo[{x,{last,lastlast}}] = 0; for (auto i:fsh[x]) { int c=dp(x+1, i, last); if(x>0) if(y>=last||y<max(i,lastlast)) c+=a[{x-1,y}]; if(x==N-1) for (int y = i; y < last; y++) c+=a[{x,y}]; memo[{x,{last,lastlast}}]=max(c, memo[{x,{last,lastlast}}]); } return memo[{x,{last,lastlast}}]; } long long max_weights(signed n, signed m, std::vector<signed> X, std::vector<signed> Y, std::vector<signed> W) { N=n; M=m; fsh.resize(N+1, vector<int>(1,0)); for (int i = 0; i < M; i++){ a[{X[i],Y[i]}] = W[i]; fsh[X[i]+1].push_back(Y[i]+1); if(X[i]>0) fsh[X[i]-1].push_back(Y[i]+1); } for (int i = 0; i < N; i++) sort(fsh[i].begin(),fsh[i].end()); int p=dp(0,0,0); return p; }

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

fish.cpp: In function 'long long int dp(long long int, long long int, long long int)':
fish.cpp:18:16: error: 'y' was not declared in this scope
   18 |     if(x>0) if(y>=last||y<max(i,lastlast)) c+=a[{x-1,y}];
      |                ^
fish.cpp:18:48: error: no match for 'operator[]' (operand types are 'std::map<std::pair<long long int, long long int>, long long int>' and '<brace-enclosed initializer list>')
   18 |     if(x>0) if(y>=last||y<max(i,lastlast)) c+=a[{x-1,y}];
      |                                                ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from fish.cpp:2:
/usr/include/c++/10/bits/stl_map.h:492:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<long long int, long long int>; _Tp = long long int; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = long long int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<long long int, long long int>]'
  492 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:492:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<long long int, long long int>&'}
  492 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_map.h:512:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::pair<long long int, long long int>; _Tp = long long int; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<const std::pair<long long int, long long int>, long long int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = long long int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<long long int, long long int>]'
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:512:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::map<std::pair<long long int, long long int>, long long int>::key_type&&' {aka 'std::pair<long long int, long long int>&&'}
  512 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~