Submission #232325

#TimeUsernameProblemLanguageResultExecution timeMemory
232325ksun48Railway Trip (JOI17_railway_trip)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; int next[2][100000][101]; // next stop of level <= j, you are <= j+1 (taking trains of j+1) int idx[100000][101]; int main(){ cin.sync_with_stdio(0); cin.tie(0); //int next[2][1000][20]; // next stop of level <= j, you are <= j+1 (taking trains of j+1) //int idx[1000][21]; int n, k, q; cin >> n >> k >> q; vector<int> level(n); for(int i = 0; i < n; i++){ cin >> level[i]; level[i] = k - level[i]; } vector<pair<int,int> > queries; for(int i = 0; i < q; i++){ int a, b; cin >> a >> b; a--; b--; queries.push_back({a,b}); } for(int j = 0; j <= k; j++){ int cur = 0; for(int i = 0; i < n; i++){ if(level[i] <= j){ idx[i][j] = cur; cur++; } } } for(int j = 0; j < k; j++){ int prev = 0; for(int i = 0; i < n; i++){ if(level[i] > j+1) continue; if(level[i] <= j){ prev = i; } next[0][i][j] = prev; } prev = n-1; for(int i = n-1; i >= 0; i--){ if(level[i] > j+1) continue; if(level[i] <= j){ prev = i; } next[1][i][j] = prev; } } for(int zz = 0; zz < queries.size(); zz++){ pair<int,int> stuff[2][2]; // person, then side stuff[0][0] = stuff[0][1] = {queries[zz].first, 0}; stuff[1][0] = stuff[1][1] = {queries[zz].second, 0}; int ans = 1000000000; for(int j = k-1; j >= 0; j--){ // go to level j for(int p = 0; p < 2; p++){ pair<int,int> newstuff[2]; newstuff[0] = make_pair(next[0][stuff[p][0].first ][j], 1000000000); newstuff[1] = make_pair(next[1][stuff[p][1].first ][j], 1000000000); for(int i = 0; i < 2; i++){ pair<int,int> x = stuff[p][i]; // go left from x, go right from x; int loc = x.first; int dist = x.second; for(int dir = 0; dir < 2; dir++){ int newloc = next[dir][loc][j]; int newdist = dist + abs(idx[ loc ][j+1] - idx[ newloc ][j+1]); for(int qq = 0; qq < 2; qq++){ if(newstuff[qq].first == newloc){ newstuff[qq].second = min(newstuff[qq].second, newdist); } } } } stuff[p][0] = newstuff[0]; stuff[p][1] = newstuff[1]; } // find ans for(int i0 = 0; i0 < 2; i0++){ pair<int,int> x0 = stuff[0][i0]; for(int i1 = 0; i1 < 2; i1++){ pair<int,int> x1 = stuff[1][i1]; ans = min(ans, x0.second + x1.second + abs(idx[x0.first][j] - idx[x1.first][j])); } } } cout << ans - 1 << '\n'; } }

Compilation message (stderr)

railway_trip.cpp: In function 'int main()':
railway_trip.cpp:41:4: error: reference to 'next' is ambiguous
    next[0][i][j] = prev;
    ^~~~
railway_trip.cpp:5:5: note: candidates are: int next [2][100000][101]
 int next[2][100000][101]; // next stop of level <= j, you are <= j+1 (taking trains of j+1)
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from railway_trip.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
railway_trip.cpp:49:4: error: reference to 'next' is ambiguous
    next[1][i][j] = prev;
    ^~~~
railway_trip.cpp:5:5: note: candidates are: int next [2][100000][101]
 int next[2][100000][101]; // next stop of level <= j, you are <= j+1 (taking trains of j+1)
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from railway_trip.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
railway_trip.cpp:61:29: error: reference to 'next' is ambiguous
     newstuff[0] = make_pair(next[0][stuff[p][0].first ][j], 1000000000);
                             ^~~~
railway_trip.cpp:5:5: note: candidates are: int next [2][100000][101]
 int next[2][100000][101]; // next stop of level <= j, you are <= j+1 (taking trains of j+1)
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from railway_trip.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
railway_trip.cpp:62:29: error: reference to 'next' is ambiguous
     newstuff[1] = make_pair(next[1][stuff[p][1].first ][j], 1000000000);
                             ^~~~
railway_trip.cpp:5:5: note: candidates are: int next [2][100000][101]
 int next[2][100000][101]; // next stop of level <= j, you are <= j+1 (taking trains of j+1)
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from railway_trip.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
railway_trip.cpp:69:20: error: reference to 'next' is ambiguous
       int newloc = next[dir][loc][j];
                    ^~~~
railway_trip.cpp:5:5: note: candidates are: int next [2][100000][101]
 int next[2][100000][101]; // next stop of level <= j, you are <= j+1 (taking trains of j+1)
     ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from railway_trip.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~